gpt4 book ai didi

c# - 登录后使用 oidc 和浏览器后退按钮的带有 azure 广告的 netcore 导致异常

转载 作者:行者123 更新时间:2023-12-04 00:38:29 29 4
gpt4 key购买 nike

所以我有一个新创建的 netcore 应用程序链接到我的 azure 事件目录帐户,中间件设置如下:

       app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AutomaticAuthenticate = true,
AutomaticChallenge = true
});

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ClientId = Configuration["Authentication:AzureAd:ClientId"],
Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],
Events = new OpenIdConnectEvents
{
OnAuthenticationFailed = OnAuthenticationFailed,
OnAuthorizationCodeReceived = OnAuthorizationCodeReceived
}
});

我的回调路径默认为“CallbackPath”:“/signin-oidc”,我在 url 上的 azure 登录是 http://localhost:20352/回复网址为 http://localhost:20352/signin-oidc

现在我可以很好地完成登录过程,但是如果您多次点击浏览器后退按钮,我就会遇到这种情况:

处理请求时发生未处理的异常。

异常(exception):关联失败。
未知位置

AggregateException:未处理的远程故障。 (关联失败。)
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__5.MoveNext()

我如何或在哪里可以捕获此异常以相应地处理它?或者我的中间件设置有什么问题导致了这种情况。

上面的两个事件永远不会被命中。

编辑:了解浏览器后退按钮的弹出 URL 是“ http://localhost:20352/signin-oidc”可能会有所帮助

这显然不作为有效的 Controller / Action 路由存在

最佳答案

单击后退按钮时出现此错误是由于浏览器重新使用对身份提供者的授权端点的调用,旧的 Nonce 和 State 参数不再有效。

当您的应用程序发出身份验证质询并启动到您的身份提供者的重定向时,它会临时存储这些值,以便它可以验证在回调中获得的响应和 token 是否有效。这就是“相关性”的含义。

未调用您的事件处理程序的原因是您想要处理 RemoteFailure 事件,例如重定向到错误屏幕:

public class AuthenticationEvents : OpenIdConnectEvents
{
public override Task RemoteFailure(FailureContext context)
{
context.HandleResponse();
context.Response.Redirect("/Home/Error");
return Task.FromResult(0);
}
}

关于c# - 登录后使用 oidc 和浏览器后退按钮的带有 azure 广告的 netcore 导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37981428/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com