2016-04-06 25 views
6

我使用Strava作爲我的外部登錄提供程序(我認爲這與Strava無關,可能是谷歌或Facebook)運行幾個小時/幾天甚至幾周GetExternalLoginInfoAsync返回null。我讀過一系列其他問題,但沒有找到解決方案。我發佈了我的整個ConfigureAuth方法,以防萬一我的訂單出錯了。GetExternalLoginInfoAsync()loginInfo返回null - 但僅在幾個小時後

如果你有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

+0

我想知道如果代碼在磁盤上的某處緩存壞auth數據。當您重新部署您的站點時,磁盤上的所有文件都將被刪除並替換爲新的文件,這可以解釋爲什麼之後認證開始起作用,而僅僅重置網站並不會執行任何操作。 –

+0

有趣的理論。任何想法要檢查什麼? – Larsi

+0

@ZainRizvi感謝您關注此事。這是一個普通的mvc站點,默認實現了身份驗證,我所做的唯一修改是將Strava作爲外部身份驗證提供程序添加。如果你能幫我弄清楚問題是什麼,我會非常高興。再次感謝您的時間 – Larsi

回答

8

我有同樣的問題。谷歌搜索後,我發現這是Owin中的一個已知錯誤,因爲他們處理cookies的方式。

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問題有關此漏洞的詳細信息,並讓我知道這很適合你。

+1

謝謝,我只是把它放在生產 - 我會讓你知道,如果它在幾周內工作 – Larsi

+2

https://xkcd.com/979/ – oflahero

+0

@spudnick哈哈。感謝您的提醒。過去3個月它一直在努力工作。完全沒有問題! – Larsi

相關問題