GetExternalLoginInfoAsync() loginInfo 返回 null - 但仅在几个小时后

GetExternalLoginInfoAsync() loginInfo return null - but only after a few hours(GetExternalLoginInfoAsync() loginInfo 返回 null - 但仅在几个小时后)
本文介绍了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 团队,但看起来他们不会在全部.有很多解决方法,但这是我能找到的最简单的:

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)