IdentityServer4 - 发生安全错误

IdentityServer4 - A security error has occured

我将 IdentityServer4 与 ASP .NET Core WebAPI 一起使用,但我在以编程方式访问发现页面时遇到问题

var disco = await DiscoveryClient.GetAsync("https://<api>:1337");

如果我在我的本地主机上托管 API 的(IdentityServer 和受保护的 API),一切正常,我什至不需要使用 https....可能它不需要如果主机名是 localhost,是否抛出 ..HTTPS is required

因此,我开始在服务器的 IIS 上创建一个自签名证书,并将其存储在个人证书存储中。 但是当我从外部(浏览器)连接时,出现错误:

This site is not secure - Error Code: DLG_FLAGS_SEC_CERT_CN_INVALID 

经过一些搜索但没有找到任何东西,我在我的笔记本电脑上安装了相同的证书(这样我就可以访问 API 而不会收到警告)。 现在我没有收到任何警告,发现 JSON 可用。可见(从浏览器)

但以编程方式我仍然遇到相同的错误。

错误

Error connecting to https://:1337/.well-known/openid-configuration: An error occurred while sending the request.

异常 StackTrace

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.DiagnosticsHandler.<SendAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at IdentityModel.Client.DiscoveryClient.<GetAsync>d__17.MoveNext()

InnerException 消息:

A security error occurred

内部异常 StackTrace

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()

编辑 01 将相同的自签名证书从服务器添加到我的笔记本电脑到受信任的证书容器上,部分有效。

安装自签名证书后(对于 IIS)我遇到了另一个错误,它与 JWT 签名的自签名证书有关,我必须将权限分配给应用程序池后面的域用户(不是 ApplicationPoolIdentity)用于证书上的 Read/Write。 我已经通过 MMC