Azure AD API returns System.Security.Principal.GenericIdentity.IsAuthenticated 始终为 false

Azure AD API returns System.Security.Principal.GenericIdentity.IsAuthenticated as false always

我正在尝试集成我的 Web 服务以使用 Azure AD 进行身份验证。来自 Azure AD 的响应每次都不同。当我在 firefox 普通浏览器中打开我的网站时,IsAuthenticated 为真。

IsAuthenticatedAsTrue

在私人浏览器中打开,IsAuthenticated 为假。

IsAuthenticatedAsFalse

我能看到的唯一区别是,IsAuthenticated true 来自 ClaimsIdentity,IsAuthenticated false 来自 GenericIdentity。

以下是我的startup.auth代码。

public partial class Startup
{
    private static string clientId = ConfigurationManager.AppSettings["ClientId"];
    private static string aadInstance = ConfigurationManager.AppSettings["AADInstance"];
    private static string tenantId = ConfigurationManager.AppSettings["TenantId"];
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["PostLogoutRedirectUri"];
    private static string authority = aadInstance + tenantId;

    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri
            });
    }
}

以下是我向 AzureAD 发送身份验证请求的代码

    public void LoginUsingAzure()
    {
        HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
                OpenIdConnectAuthenticationDefaults.AuthenticationType);
    }

我正在尝试重现此问题,但失败了。我正在使用全新安装的 50.1.0 版本测试 Web 应用程序。

要解决此问题,我建议您 re-install 使用此版本的 Firefox。

测试图供大家参考:

此问题已解决。这个问题的原因是依赖性问题。在下面的 Whosebug link.

中找到了答案

ASP.NET_SessionId + OWIN Cookies do not send to browser

正在安装 Kentor.OwinCookieSaver - 版本 1.1.0 nuget 包,解决了我的问题。