简体   繁体   English

检索用户声明

[英]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: 我已经在startup.auth.cs文件中实现UseOpenIdConnectAuthentication来启用AAD身份验证,并且在成功登录以下代码后,我正在检索用户身份:

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. 当我在azure上发布站点并在azure门户上启用应用程序身份验证时(而不是使用UseOpenIdConnectAuthentication代码),身份验证似乎可以正常工作。 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. Easy Auth(Azure功能的身份验证/授权)和OWIN组件都可以为您的Web应用程序提供身份验证。 If you doesn't use both of them, then you need to complement the authentication yourself for the web app. 如果您不同时使用它们,那么您需要自己补充Web应用程序的身份验证。 Otherwise, there is no claims you can retrieve. 否则,您将无法获得任何索赔。

More detail about the Easy Auth feature, you can refer the blogs of cgillum. 有关Easy Auth功能的更多详细信息,您可以参考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 . 并且,如果您要在不使用Azure AD的情况下构建声明应用程序,则可以参考文档如何:使用基于表单的身份验证来构建声明感知的ASP.NET应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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