gpt4 book ai didi

c# - OWIN OpenID 提供程序 - GetExternalLoginInfo() 返回 null

转载 作者:太空狗 更新时间:2023-10-29 22:05:36 24 4
gpt4 key购买 nike

我在使用 ASP.NET Identity 并基于具有个人用户帐户身份验证的 VS2013 模板的 ASP.NET MVC5 应用程序中遇到 OWIN OpenId 提供程序问题。 Google 和 LinkedIn 的 OWIN OpenID 提供商用于登录身份验证。

问题是看起来很随意;即使登录身份验证成功,GetExternalLoginInfo() 也会在 LoginConfirmation 回调中返回 null。

var authManager = HttpContext.Current.GetOwinContext().Authentication;
var login = authManager.GetExternalLoginInfo();

正在使用的提供商是 Google (Microsoft.Owin.Security.Google 2.1.0) 和 LinkedIn(来自 Owin.Security.Providers 1.3),这两个提供商都会导致同样的问题。

有时它会失败一次然后再次运行,但有时它会一直失败直到 AppPool 被回收。

目前,该应用程序的两个实例托管在同一 Windows Azure 虚拟机上的 IIS 中。每个实例都有自己的 AppPool 但设置相同(不同的子域)。有时,登录在一个实例上停止工作,但仍在另一个实例上工作。

该问题也已在本地重现(IIS Express - VS2013)。

有人在使用 OWIN OpenID 身份验证时遇到过类似问题吗?

Startup.Auth.cs 看起来像这样:

public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

app.UseGoogleAuthentication();

app.UseLinkedInAuthentication("clientId", "clientSecret");
}

正在使用以下 OWIN nuget 包:

  <package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.ActiveDirectory" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Jwt" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Owin.Security.Providers" version="1.3" targetFramework="net45" />
<package id="System.IdentityModel.Tokens.Jwt" version="3.0.2" targetFramework="net45" />

最佳答案

当缺少 ASP.NET_SessionId cookie 时会出现问题。

在重定向到 OpenID 提供商以获取凭据之前在 session 中设置一个虚拟值似乎可以解决问题:

[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
Session["dummy"] = "dummy"; // Create ASP.NET_SessionId cookie

return View();
}

此答案中有更多详细信息:https://stackoverflow.com/a/21234614/205023

关于c# - OWIN OpenID 提供程序 - GetExternalLoginInfo() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22535146/

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