[英]asp identity owin with openid login issue
我在 MVC 5 项目 (OWIN 4.2.0) 上使用 OWIN 包
我使用的三个主要包是: Microsoft.Owin.Security.OpenIdConnect
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Host.SystemWeb
我遇到的问题是在一段时间后,用户无法再通过 OpenId 登录,直到我重新启动应用程序。 (登录打开 ID 成功,但 ExternalLoginInfoAsync 始终返回 null)我目前只设置了一个外部登录提供程序。
[AllowAnonymous]
public async Task<ActioNResult> ExternalLoginCallback(string returnUrl)
{
// this will return null after some times on next login
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
}
public ActionResult ExternalLogin(string provider, string returnUrl)
{
ControllerContext.HttpContext.Session.RemoveAll();
Session["Workaround"] = 0;
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
我在网上测试了一些建议,包括使用:
但这都不起作用。 当用户重新登录一段时间后,它会在 GetExternalLoginInfoAsync() 中返回 null。
发生这种情况的时间不一致,并且在我重新启动服务器之前用户将无法登录(即使清除浏览器历史记录也不行)
我现在完全没有想法了。 希望有人能与我分享一些见解。
我的启动代码如下
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
SlidingExpiration = true,
CookieManager = new SystemWebCookieManager(),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(5),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
ExpireTimeSpan = TimeSpan.FromMinutes(5)
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
MetadataAddress = metadataAddress,
RedirectUri = postLogoutRedirectUri,
PostLogoutRedirectUri = postLogoutRedirectUri,
ResponseType = OpenIdConnectResponseType.CodeIdToken,
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
SaveTokens = true,
UseTokenLifetime = true,
AuthenticationMode = AuthenticationMode.Passive
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.