使用OWIN中间件的Azure OpenID Connect导致无限重定向循环。
使用OWIN中间件的Azure OpenID Connect导致无限重定向循环。
我已经使用OWIN中间件在我的ASP.NET MVC应用程序中设置了OpenID Connect身份验证。
正如Fiddler输出所显示的那样,通过Azure OpenID Connect成功登录后,浏览器不断在我的site.azurewebsites.net和login.windows.net之间来回循环。
我已确保以下密钥正确匹配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日
我昨晚在一个ASP.NET Framework 4.5.1 MVC应用程序中遇到了这个问题,对我来说有两个问题。
-
尝试使用HTTP而不是HTTPS访问站点
- 我有本地主机、开发、测试(当然还有产品)环境在HTTPS下运行,所以我不必担心本地处理HTTP。我在所有地方都运行了HSTS,这解决了这个问题。有关更多信息,请参见在asp.net中强制整个站点使用https的最佳方法?
-
Cookie覆盖,如https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues所述
- 对我有用的是重新配置CookieAuthenticationMiddleware以直接写入到System.Web的cookie集合修复和Katana 3.1.0有几个ICookieManager的实现可用。旧版本可以使用以下修复。
我是一个“我尝试了所有但没有什么作用”的开发者,直到我发现那个修复。希望这对你也有用。