gpt4 book ai didi

asp.net-mvc-5 - 指定重定向时 AAD 身份验证后的无限重定向循环

转载 作者:行者123 更新时间:2023-12-03 23:56:48 25 4
gpt4 key购买 nike

如果我像这样在 OpenIdConnectAuthenticationOptions 中指定重定向 URI

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = redirectUri,

Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});

然后我得到一个无限的重定向循环。这只发生在我把它放在独立的 IIS 服务器(我们的测试服务器)上时。如果我删除 AAD 中的所有重播 url 并只为测试服务器设置它,并从上面删除“RedirectUri = redirectUri”,我的问题就会消失。

我这里有一个 fiddler 日志: https://drive.google.com/file/d/0B5Ap95E_wdyAa0RLLWloZ0dCaGM/view?usp=sharing

看来,当来自 AAD 的请求返回到我的应用程序时,在 token 被抓取和使用之前,中间件只是用 302 将其弹回。另外,可能重要的是,我在 mvc 上有 [Authorize] 属性路由和返回 uri 指向的 Controller 。如果我删除它,我不会遇到这个问题。

[更新]
我尝试将应用程序移动到 IIS 的 localhost 安装,而不是使用 iisexpress,这样我就可以像在 iis 服务器上一样设置为子应用程序。在我的本地主机上,它执行相同的无限循环。我在 [Authorize] 属性的覆盖上添加了一些遥测自定义事件,并且能够发现在身份验证后页面被重定向回应用程序 httpContext.user.identity.IsAuthenticated = false。那么不知何故 OWIN 中间件没有将其设置为 true?

谢谢你的帮助!

最佳答案

我能够找到解决我的问题的方法。最初我指定我的回复网址指向网站的根目录。我的溃败配置如下所示:

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Welcome", action = "Index", id = UrlParameter.Optional }
);

如果我在回复 url 的末尾附加“欢迎”,它会起作用。出于某种原因,如果我将回复 url 留在站点的根目录并选择默认路由,它只会进入无限循环。

我还发现这仅适用于站点的子应用程序。我尝试将我的应用程序移动到 iis 中的独立站点,而不是我不必在回复 url 中添加 Controller 名称。

例子:
原回复网址:
mysite.mydomain.com/CustomApp

新回复网址:
mysite.mydomain.com/CustomApp/Welcome

希望其他人能发现这很有用!

更新

我发现问题的根源仍然是由这个 mvc5 bug 引起的:katanaproject.codeplex.com/workitem/197。我以为它已经修复了但它没有,所以我将继续使用著名的 Kentor Owin Cookie Saver:github.com/Sustainsys/owin-cookie-saver

关于asp.net-mvc-5 - 指定重定向时 AAD 身份验证后的无限重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44397715/

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