簡體   English   中英

AuthenticationManager.GetExternalLoginInfoAsync() 始終為空

[英]AuthenticationManager.GetExternalLoginInfoAsync() always null

ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

為什么這一行必須總是返回 null? 當用戶嘗試使用任何提供程序登錄時,就會發生這種情況。 我知道 FLOW 是正確的,因為它實際上在本地工作,但是當我部署網站時,它總是返回 null。

據我所知,它是使用外部 cookie 來跟蹤這一點的,我可以確定它不是瀏覽器,因為它在同一瀏覽器上本地工作。

所有提供商都會發生這種情況,即使我已經仔細檢查過所有提供商在每個相應的控制面板中都將域設置為“允許”。 就像我說的一切都在本地工作。

我已經嘗試按照某些答案的建議重新啟動 IIS。

在 Startup.Auth.cs 中也有這些行,並正確設置了 cookie domian

 app.UseCookieAuthentication(new CookieAuthenticationOptions
  {
       CookieDomain = ".example.com",
            ...
  });

  //use a cookie to temporarily store information about a user logging in with a third party login provider
  app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

確保您的(facebook、twitter 等)提供商設置在部署時未被覆蓋。

還要確保您的回調 url 已在提供商處正確注冊。 我正在使用 LinkedIn,它需要一個完整的 url 到您的回調,例如。 https://domain.com/signin-linkedin

我有以下設置,可以正常工作:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    CookieSecure = CookieSecureOption.SameAsRequest,
    CookieName = "CustomCookieName",
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
            validateInterval: TimeSpan.FromMinutes(30),
            regenerateIdentity: (manager, user) => Some.Custom.Identity.Helper.GenerateUserIdentityHelperAsync(user, manager)) // This helper method returns ClaimsIdentity for the user
    }
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM