如何在Azure Ad B2c中获取用户个人资料详细信息 [英] How to get user profile details in azure ad b2c

查看:237
本文介绍了如何在Azure Ad B2c中获取用户个人资料详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的MVC Web应用程序使用Azure AD B2C身份验证.我已经开发了该项目的登录部分.现在,我想在用户登录Web应用程序时获取用户的详细信息.我看过一些说明如何编辑用户详细信息的文章.但是我找不到与获取用户个人资料数据相关的任何内容.请帮忙.

I'm using Azure AD B2C authentication for my MVC web application. I have developed the sign-in part of the project. Now I want to get the user's details when a user logs into the web app. I have seen some of the articles which explain how to edit user details. But I couldn't find anything related to get user profile data. Please Help.

这是我的登录操作.

public ActionResult SignIn()
{
    if (!Request.IsAuthenticated)
    {
        var authenticationManager = HttpContext.GetOwinContext().Authentication;
        authenticationManager.Challenge(new AuthenticationProperties() { RedirectUri = "/" }, Startup.SignInPolicyId); 
        return Content("");
    }
    else
    {
        return Redirect("~/Home/Login");
    } 
}

推荐答案

在B2C策略中,您需要添加声明.

Within the B2C policy you need to add claims.

选择策略->编辑->应用程序声明->选择所需的内容->保存.

Select the policy -> Edit -> Application Claims -> Select the ones you want -> save.

当用户登录时,这些将添加到其令牌中.登录后,您可以在代码中枚举它们.:

When a use signs in, these will be added to their token. You can then enumerate them within your code after they have logged in.:

var claimsIdentity = (System.Security.Claims.ClaimsIdentity)User.Identity;
foreach (var claim in claimsIdentity.Claims)
{
     // do stuff with claim.Type & claim.Value
}

这篇关于如何在Azure Ad B2c中获取用户个人资料详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆