使用OWIN中间件的Azure OpenID Connect导致无限重定向循环。

9 浏览
0 Comments

使用OWIN中间件的Azure OpenID Connect导致无限重定向循环。

我已经使用OWIN中间件在我的ASP.NET MVC应用程序中设置了OpenID Connect身份验证。

正如Fiddler输出所显示的那样,通过Azure OpenID Connect成功登录后,浏览器不断在我的site.azurewebsites.net和login.windows.net之间来回循环。

\"Fiddler

我已确保以下密钥正确匹配Azure AD信息



我的Start.cs代码如下所示

 private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
    private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
    private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
    private string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
    IAuthorizationService authorizationService = new AuthorizationService();
    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions()
        {
            ExpireTimeSpan =TimeSpan.FromMinutes(15)
        });
        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri}
            });
    }
}

不确定是什么原因导致不断重定向。我已在MVC Controller上放置了一个[Authorize]特性,用于Post验证重定向网址。

admin 更改状态以发布 2023年5月25日
0
0 Comments

这里发生的事情与JuneT注意到的相关。这与CookieAuthenticationOptions.CookieSecure == CookieSecureOption.SameAsRequest的默认设置有关。由于您从http开始,最终重定向的是http。创建“authcookie”的请求来自AAD的https。

我能够通过设置CookieSecure == CookieSecureOption.Always来使其工作。这意味着cookie可能会随着您的身份验证泄漏。

是否必须有一种方法来确保仅进行身份验证的页面只接受https连接。

0
0 Comments

我昨晚在一个ASP.NET Framework 4.5.1 MVC应用程序中遇到了这个问题,对我来说有两个问题。

  1. 尝试使用HTTP而不是HTTPS访问站点

  2. Cookie覆盖,如https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues所述

    • 对我有用的是重新配置CookieAuthenticationMiddleware以直接写入到System.Web的cookie集合修复和Katana 3.1.0有几个ICookieManager的实现可用。旧版本可以使用以下修复。

我是一个“我尝试了所有但没有什么作用”的开发者,直到我发现那个修复。希望这对你也有用。

0