【发布时间】:2020-11-12 16:40:59
【问题描述】:
我有一个配置为使用 OIDCAuthentication 的 ASP.Net Core 3.1 应用程序,如下:
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Authority = appSettings.OIDCAuthority;
options.ClientId = appSettings.OIDCClientId;
options.ClientSecret = appSettings.OIDCClientSecret;
options.ResponseType = OpenIdConnectResponseType.Code;
options.Scope.Add("profile");
options.SaveTokens = true;
options.Events = new OpenIdConnectEvents
{
OnAuthenticationFailed = (context) =>
{
return System.Threading.Tasks.Task.CompletedTask;
},
OnRemoteFailure = (context) =>
{
return System.Threading.Tasks.Task.CompletedTask;
},
请注意,我已经连接到 OnRemoteFailure 和 OnAuthenticationFailed 事件,每个处理程序上都有断点。
我试图弄清楚如何处理 OIDC 服务器停机的情况。因此,我在本地调试环境中通过不运行 Identity Server 项目来模拟这一点。当 .Net Core 应用程序重定向到 OIDC 服务器进行身份验证时,会出现以下错误:
处理请求时发生未处理的异常。 SocketException: 由于目标机器主动拒绝,无法建立连接。
我理解为什么抛出异常,但我不清楚如何处理它以便向用户显示更友好的错误。我想我可以在更全局的异常处理程序中做到这一点? (仍然需要调查),但我希望至少应该命中上述断点之一?关于为什么它们不会被命中的任何想法?这种情况肯定符合OnRemoteFailure 事件吗?
【问题讨论】:
-
我的回答可以接受吗?
标签: openid-connect asp.net-core-3.1