GetExternalLoginInfoAsync()loginInfo返回null-但仅在几个小时后 [英] GetExternalLoginInfoAsync() loginInfo return null - but only after a few hours

查看:293
本文介绍了GetExternalLoginInfoAsync()loginInfo返回null-但仅在几个小时后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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 Team,但看来他们无法解决此问题全部.有很多解决方法,但这是我能找到的最简单的方法:

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-但仅在几个小时后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆