如何在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
}