为什么在闲置约40分钟后我的请求开始失败?
我建立了与https://github.com/Azure-Samples/active-directory-dotnet-webapp-groupclaims中相同的身份验证机制(我正在使用Asp.Net MVC4:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = ConfigHelper.ClientId,
Authority = ConfigHelper.Authority,
PostLogoutRedirectUri = ConfigHelper.PostLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = async context =>
{
ClientCredential credential = new ClientCredential(ConfigHelper.ClientId, ConfigHelper.AppKey);
string userObjectId = context.AuthenticationTicket.Identity.FindFirst(Globals.ObjectIdClaimType).Value;
AuthenticationContext authContext = new AuthenticationContext(ConfigHelper.Authority, new TokenDbCache(userObjectId));
AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
context.Code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, ConfigHelper.GraphResourceId);
},
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error/ShowError?signIn=true&errorMessage=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
}
我正在使用angular2 SPA应用程序,并且在一段时间不活动之后,当应用程序尝试发送请求时,此请求失败(在chrome工具中,我看到API请求已重定向到身份验证服务器(azure aad),但服务器未正确处理它们并且我在客户端看到了身份验证服务器的响应。)
如果刷新页面,一切正常。
我已经禁用了IIS回收并设置了iddleTimout = 0。
在web.config中,我禁用了默认身份验证:
<authentication mode="None" />
<sessionState timeout="1440">
事实证明,如果OpenIdConnectAuthenticationOptions UseTokenLifetime
将其设置为true,则cookie过期时间设置将被忽略。另外,我发现我正在使用默认情况下将此设置设置为true的库。此默认行为已更改,现在UseTokenLifetime默认情况下设置为false:https : //github.com/aspnet/Security/commit/966fa6672ff3c5bd75703c325512778722ff46a2#diff-c130fbf3a8ec2c0c32beaf27fcf04ea9
所以
new OpenIdConnectAuthenticationOptions
{ UseTokenLifetime = false }
解决了我的问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句