gpt4 book ai didi

c# - AuthenticationManager.GetExternalLoginInfoAsync() 始终为空

转载 作者:行者123 更新时间:2023-11-30 17:43:33 25 4
gpt4 key购买 nike

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

关于c# - AuthenticationManager.GetExternalLoginInfoAsync() 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30771739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com