我正在将Azure-AD集成添加到MVC Web应用程序中。当我在本地运行它时一切正常,我可以登录,注销,应用程序按预期运行。但是,当我部署(AWS)并尝试访问该页面时,我收到以下错误:
ERR_TOO_MANY_REDIRECTS
我已经尝试过跟踪重定向,似乎我去的任何页面都在循环中重定向(302)到自身。永远不会到达登录页面,即使标记为允许匿名访问,我也无法访问任何页面。
我已经在使用其他地方推荐的app.UseKentorOwinCookieSaver();
修补程序但是没有效果。任何建议将不胜感激。
根据请求,这是Startup.Auth.cs
中的身份验证代码:
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseKentorOwinCookieSaver();
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthorizationCodeReceived = (context) =>
{
var code = context.Code;
ClientCredential credential = new ClientCredential(clientId, appKey);
string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
SetUserInfoCookie(context.AuthenticationTicket.Identity.Name);
AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
return Task.FromResult(0);
}
}
});
}
这是用户点击按钮时调用身份验证的代码。这在本地工作时按预期工作,但我无法访问页面以在部署后运行此代码:
[AllowAnonymous]
private ActionResult SignInWithAzureAd(string returnUrl)
{
System.Web.HttpContext.Current.GetOwinContext().Authentication.Challenge();
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext()
.Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
return null;
}