Aru*_*run 4 core identityserver4
如何在IIS中使用IdentityServer4托管ASPNET CORE APP.该应用程序从localhost运行良好,但不是IIS中的Web应用程序设置.
例如,
http:// localhost:5000/connect/token正在运行,但http://example.com/myauthapp/connect/token无法访问 - 当使用身份模型或邮递员从控制台应用程序尝试时,返回500 - 内部服务器错误.我可以使用网络浏览器登录应用程序,但不能通过控制台应用程序或邮递员登录.
进一步排除故障,我发现如下.
An unhandled exception has occurred: IDX10638: Cannot created the SignatureProvider, 'key.HasPrivateKey' is false, cannot create signatures. Key: Microsoft.IdentityModel.Tokens.RsaSecurityKey.
System.InvalidOperationException: IDX10638: Cannot created the SignatureProvider, 'key.HasPrivateKey' is false, cannot create signatures. Key: Microsoft.IdentityModel.Tokens.RsaSecurityKey.
at Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey key, String algorithm, Boolean willCreateSignatures)
at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(SecurityKey key, String algorithm, Boolean willCreateSignatures)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateEncodedSignature(String input, SigningCredentials signingCredentials)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token)
at IdentityServer4.Services.DefaultTokenCreationService.CreateJwtAsync(JwtSecurityToken jwt)
at IdentityServer4.Services.DefaultTokenCreationService.<CreateTokenAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
正如Arun在评论中指出的那样,证书必须安装在服务器上.
1.要首先在localhost上测试它,请确保使用"AddSigningCredential"而不是"AddTemporarySigningCredential".
services.AddIdentityServer()
.AddSigningCredential(new X509Certificate2(Path.Combine(_environment.ContentRootPath, "certs", "IdentityServer4Auth.pfx")));
//.AddTemporarySigningCredential()
;
Run Code Online (Sandbox Code Playgroud)
"C:\ Program Files(x86)\ Windows Kits\8.1\bin\x64\makecert"-n"CN = IdentityServer4Auth"-a sha256 -sv IdentityServer4Auth.pvk -r IdentityServer4Auth.cer -b 01/01/2017 -e 2025年1月1日
"C:\ Program Files(x86)\ Windows Kits\8.1\bin\x64\pvk2pfx"-pvk IdentityServer4Auth.pvk -spc IdentityServer4Auth.cer -pfx IdentityServer4Auth.pfx
在localhost上测试
如果成功,请部署到iis服务器,双击服务器在服务器上安装证书,然后进行测试.
确保应用程序池"加载用户配置文件"设置为true:
重启IIS
如果这与500失败,就像我一样(并且没有日志可以帮助你),试试这个.要解决此问题,请在certs文件夹中的步骤2中重新创建服务器上的证书.双击要安装的证书.如果您没有安装Visual Studio,则可能必须安装开发人员工具包:https: //developer.microsoft.com/en-us/windows/downloads/windows-8-1-sdk
| 归档时间: |
|
| 查看次数: |
4531 次 |
| 最近记录: |