Mik*_*ike 5 katana asp.net-mvc-5 azure-active-directory adal openid-connect
如果我在 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);
}
}
});
Run Code Online (Sandbox Code Playgroud)
然后我得到一个无限的重定向循环。只有当我将它放在独立的 IIS 服务器(我们的测试服务器)上时才会发生这种情况。如果我删除 AAD 中的所有重播 url,并仅将其设置为测试服务器,并删除上面的“RedirectUri = redirectUri”,我的问题就会消失。
我这里有一个小提琴手日志:https://drive.google.com/file/d/0B5Ap95E_wdyAa0RLLWloZ0dCaGM/view ?usp=sharing
看起来,当来自 AAD 的请求返回到我的应用程序时,在获取和使用令牌之前,中间件只是用 302 将其弹回。另外可能重要的是,我在 mvc 上具有 [Authorize] 属性路由和返回 uri 指向的控制器。如果我删除它,我就不会遇到这个问题。
[更新] 我尝试将应用程序移动到 IIS 的本地主机安装,而不是使用 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 }
);
Run Code Online (Sandbox Code Playgroud)
如果我将“欢迎”附加到回复网址的末尾,它就会起作用。出于某种原因,如果我将回复 URL 保留到网站的根目录并选择默认路由,它就会进入无限循环。
我还发现这仅适用于网站的子应用程序。我尝试将我的应用程序移动为 iis 中的独立站点,而不是在回复 url 中添加控制器名称。
示例:
原始回复网址:
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
| 归档时间: |
|
| 查看次数: |
6964 次 |
| 最近记录: |