C# DiscoveryClient.GetAsync失败“;发卡机构名称与授权机构不匹配”;当调用通过SSL终止符时
我们的web应用程序托管在SSL终止集群后面。我调用C# DiscoveryClient.GetAsync失败“;发卡机构名称与授权机构不匹配”;当调用通过SSL终止符时,c#,ssl,identityserver4,C#,Ssl,Identityserver4,我们的web应用程序托管在SSL终止集群后面。我调用DiscoveryClient.GetAsync var discoveryClient = DiscoveryClient.GetAsync("https://ourcluster.net/identityserver").Result; 我得到以下结果: 颁发者名称与权限不匹配:http://ourcluster.net/identityserver 我假设SSL终止会导致IdentityServer端点以http的形式接收请求,从而相应
DiscoveryClient.GetAsync
var discoveryClient = DiscoveryClient.GetAsync("https://ourcluster.net/identityserver").Result;
我得到以下结果:
颁发者名称与权限不匹配:http://ourcluster.net/identityserver
我假设SSL终止会导致IdentityServer端点以http的形式接收请求,从而相应地解析其授权url
对如何解决这个问题有什么建议吗
-通过在承载IdentityServer端点的应用程序中设置IssuerUri,我们找到了一个可接受的解决方法:
services.AddIdentityServer(options =>
{
var issuerUri = Configuration["IdentityServer:IssuerUri"];
if (!string.IsNullOrEmpty(issuerUri))
{
options.IssuerUri = issuerUri;
}
});
因此,客户机应用程序从JWT和它们自己对IdentityServer端点的调用中获得相同的issuerUri值
-出现这种情况是因为http请求来自处于ssl终止状态的反向代理。因此,请求在代理上作为https发送,然后作为http发送到IdentityServer4 首先,在IdentityServer中,必须使用MS headers中间件,正如@leastprivilege所说的那样。您可以使用“Microsoft.AspNetCore.HttpOverrides”包中的此代码段 然后配置反向代理将
X-Forwarded-Proto
发送到上游。我们使用nginx,因此最低配置必须为:
server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;
root /var/www;
server_name id.example.com;
ssl on;
ssl_certificate /opt/certs/2017/identity-server/fullchain.pem;
ssl_certificate_key /opt/certs/2017/identity-server/privkey.pem;
access_log /var/log/nginx/id.example.com-access.log main;
error_log /var/log/nginx/id.example.com-error.log;
location / {
proxy_pass http://identity-service;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_redirect off;
}
}
您需要使用MS headers中间件使您的服务器相信它正在HTTPSWe上运行。我们研究了这种方法,但由于托管环境没有100%最终确定,因此放弃了它—许多问题仍有待改变。但我们确实使用issuerUri的固定值使事情正常运行。
server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;
root /var/www;
server_name id.example.com;
ssl on;
ssl_certificate /opt/certs/2017/identity-server/fullchain.pem;
ssl_certificate_key /opt/certs/2017/identity-server/privkey.pem;
access_log /var/log/nginx/id.example.com-access.log main;
error_log /var/log/nginx/id.example.com-error.log;
location / {
proxy_pass http://identity-service;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_redirect off;
}
}