指定重定向时,在AAD身份验证后无限重新指导循环



如果我在openIDConnectauthentication中指定了一个重定向的URI,例如So

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",则消失了。

我在这里有一个提琴手日志:https://drive.google.com/file/d/0b5ap95e_wdyaa0rllwlolz0dcagm/view?usp = sharing

看来,当aad的请求返回我的应用程序时,在抓取和使用令牌之前,中间的钢铁只是用302就会弹跳。在路由和返回URI指向的MVC控制器上。如果我删除它,我将不会得到这个问题。

[更新]我尝试将应用程序移至IIS的Localhost安装,而不是使用Iisexpress,以便可以将其设置为IIS服务器上的子应用程序。在我的本地主机上,它可以执行相同的无限循环。我在[授权]属性的覆盖中添加了一些遥测自定义事件,并能够发现当认证后,将页面重新定位回到应用程序时,httpcontext.user.inderity.isterity.isauthenticatientatientatientatienated = false。因此,某种程度上的Owin Middle Ware并没有将其设置为true?

感谢您的任何帮助!

我能够找到解决我问题的解决方案。最初,我指定我的回复URL指向网站的根源。我的Rout配置看起来像这样:

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

如果我将"欢迎"附加到答复URL的末尾,则可以正常工作。由于某种原因,如果我将答复URL留在站点的根部并拿起默认路由的路线只会进入无限环路。

我还发现这仅适用于站点的子应用程序。我尝试将应用程序移至IIS中的独立站点,而不是在回复URL中添加控制器名称。

示例:
原始答复URL:mysite.mydomain.com/customapp

新回复URL:mysite.mydomain.com/customapp/welcome

希望别人可以发现这有用!

update

我发现问题的根源仍然是由此MVC5错误引起的:katanaproject.codeplex.com/workitem/197。我以为它已经修复了,但没有修复,所以我将继续使用众所周知的肯特·欧文·饼干节省:github.com/sustapesysys/owin-cookie-saver

通过使用cookiesecureoption

使用Never Option解决了解决
app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                CookieSecure = CookieSecureOption.Never
            })

最新更新