问题描述
我使用 Strava 作为我的外部登录提供程序(我假设这与 Strava 无关,也可能是 google 或 facebook)运行几个小时/天甚至几周后 GetExternalLoginInfoAsync 返回 null.我已经阅读了许多具有相同问题的其他问题,但没有找到解决方案.我发布了我的整个 ConfigureAuth 方法,以防我对订单做错了什么.
I'm using Strava as my external login provider (I assume this is not related to Strava, could be google or facebook also) After running for a few hours / days or even weeks GetExternalLoginInfoAsync return null. I've read a bunch of other questions with the same problem, but did not find a solution. I post my entire ConfigureAuth method, just in case I did something wrong with the order.
如果您有一个 strava 帐户,您可能会在这里遇到问题:fartslek.no/Account/Login
If you have a strava account you could probably experience the problem here: fartslek.no/Account/Login
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
CookieManager = new SystemWebCookieManager()
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
app.UseStravaAuthentication( new StravaAuthenticationOptions{
ClientId="XXX",
ClientSecret= "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
});
}
我正在使用这个 https://github.com/Johnny2Shoes/Owin.Security.Strava 获取 StravaAuth.
I'm using this https://github.com/Johnny2Shoes/Owin.Security.Strava to get StravaAuth.
当它停止工作时,天蓝色重置是不够的,但如果我进行新的部署,一切都会工作一段时间.
When it stop working a azure reset is not enough, but if I do a new deploy everything works for a while.
我正在使用 Owin 3.0.1 和 Mvc 5.2.3
I'm using Owin 3.0.1 and Mvc 5.2.3
推荐答案
我也遇到了同样的问题.谷歌搜索了一下,我发现这是 Owin 中的一个已知错误,因为它们处理 cookie 的方式.
I had the same problem. After googling a little, I've discovered this is a known bug in Owin, because of the way they handle cookies.
此问题已提交给 Katana 团队,但看起来他们不会在全部.有很多解决方法,但这是我能找到的最简单的:
This issue was submitted to Katana Team, but it looks they won't fix it at all. There are many workarounds for this, but this was the simplest I could find:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
ControllerContext.HttpContext.Session.RemoveAll();
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
请参阅此 询问有关此错误的更多详细信息,并让我知道这是否适合您.
See this question for more details about this bug, and let me know if this works well for you.
这篇关于GetExternalLoginInfoAsync() loginInfo 返回 null - 但仅在几个小时后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!