Dinesh M
Dinesh M

Reputation: 1086

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

I am trying to integrate my web service to authenticate using Azure AD. The response from Azure AD varies each time. When i open my site in firefox normal browser, the IsAuthenticated as true.

IsAuthenticatedAsTrue

Opening in a private browser, the IsAuthenticated is false.

IsAuthenticatedAsFalse

The only difference i can see is, the IsAuthenticated true is from ClaimsIdentity and IsAuthenticated false is from GenericIdentity.

The following is my startup.auth code.

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

The following is my code to send the authentication request to AzureAD

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

Upvotes: 5

Views: 1342

Answers (2)

Dinesh M
Dinesh M

Reputation: 1086

This issue was fixed. The reason for this issue is dependency problem. Found the answer in the below stackoverflow link.

ASP.NET_SessionId + OWIN Cookies do not send to browser

Installing Kentor.OwinCookieSaver -Version 1.1.0 nuget package, solved my issue.

Upvotes: 1

Fei Xue
Fei Xue

Reputation: 14649

I am trying to reproduce this issue however failed. I am testing the web app using version 50.1.0 with clean installation.

To fix this issue, I suggest that you re-install the Firefox with this version.

Here is the test figure for your reference:

enter image description here

Upvotes: 0

Related Questions