简体   繁体   中英

Retrieving user claims

I have implemented UseOpenIdConnectAuthentication in the startup.auth.cs file to enable AAD authentication and I am retrieving the user identity after successful login in the following code:

private ClaimsIdentity GetIdentity(IPrincipal user)
{
    if (user == null)
    {
        return null;
    }

    if (user is ClaimsPrincipal)
    {
        return ((ClaimsIdentity)(user as ClaimsPrincipal).Identity);
    }

    return ((ClaimsIdentity)(user.Identity));
}

When I publish my site on azure and enable app Authentication on azure portal, (instead of using UseOpenIdConnectAuthentication code), the authentication seems to work fine. But now when I run my application locally, I have removed the auth code and I am not able to retrieve any user claims. Is there any work around to be able to run my application locally as well and retrieve those claims?

Is there any work around to be able to run my application locally as well and retrieve those claims?

Both Easy Auth(Authentication/Authorization of Azure feature) and OWIN component provide the authentication for your web app. If you doesn't use both of them, then you need to complement the authentication yourself for the web app. Otherwise, there is no claims you can retrieve.

More detail about the Easy Auth feature, you can refer the blogs of cgillum.

And if you mean you want to build the claims application without using Azure AD, you can refer the document How To: Build Claims-Aware ASP.NET Application Using Forms-Based Authentication .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM