加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – GetExternalLoginInfoAsync()loginInfo返回null –

发布时间:2020-12-15 20:42:17 所属栏目:asp.Net 来源:网络整理
导读:我正在使用Strava作为我的外部登录提供商(我认为这与Strava无关,也可能是google或facebook)运行几小时/几天甚至几周后,GetExternalLoginInfoAsync返回null.我已经阅读了同样问题的一堆其他问题,但没有找到解决方案.我发布了我的整个ConfigureAuth方法,以防我
我正在使用Strava作为我的外部登录提供商(我认为这与Strava无关,也可能是google或facebook)运行几小时/几天甚至几周后,GetExternalLoginInfoAsync返回null.我已经阅读了同样问题的一堆其他问题,但没有找到解决方案.我发布了我的整个ConfigureAuth方法,以防我在订单上做错了.

如果你有一个strava帐户,你可能会在这里遇到问题: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.

当它停止工作时,天蓝色的重置是不够的,但是如果我进行新的部署,一切都会工作一段时间.

我正在使用Owin 3.0.1和Mvc 5.2.3

解决方法

我有同样的问题.谷歌搜索了一下后,我发现这是Owin的一个已知错误,因为他们处理cookie的方式.

This issue被提交给Katana团队,但看起来他们根本不会修复它.有很多解决方法,但这是我能找到的最简单的方法:

[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 }));
    }

有关此错误的更多详细信息,请参阅this问题,如果适合您,请告诉我.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读