Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
    }
like image 569
Dinesh M Avatar asked Nov 08 '22 03:11

Dinesh M


1 Answers

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.

like image 178
Dinesh M Avatar answered Nov 14 '22 23:11

Dinesh M