简体   繁体   English

如何在 Azure AD B2C oauth2 登录中获取用户的对象 ID

[英]How to get user's Object ID in Azure AD B2C oauth2 login

I am using the following custom api to get access_token when the user is found in Azure AD B2C:当在 Azure AD B2C 中找到用户时,我使用以下自定义 api 来获取 access_token:

https://patient360app.b2clogin.com/patient360app.onmicrosoft.com/oauth2/v2.0/token?p=B2C_1_ROPC_Auth

and it is returning me the following response:它返回给我以下回复:

在此处输入图片说明

how can I get user's Object ID with the above response?如何通过上述响应获取用户的对象 ID?

The id_token property of the authentication response is set to an encoded JSON Web Token (JWT). 身份验证响应的id_token属性设置为已编码的JSON Web令牌(JWT)。

You should validate this ID token using one of the JWT libraries that is listed at https://jwt.io/ and then you can read the oid (object identifier) claim from the validated token. 您应该使用https://jwt.io/上列出的JWT库之一来验证此ID令牌,然后可以从已验证的令牌中读取oid (对象标识符)声明。

The way I went about this is within my api controller I did the following: 我进行此操作的方式是在我的api控制器中执行以下操作:

User.Claims.First(e => e.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

That gave me the user id within the token provided to the api call. 这给了我提供给api调用的令牌内的用户ID。

I used the following instead of hard-coding the schema:我使用以下而不是硬编码模式:

var objectIdIsNameIdentifier = User.FindFirstValue(ClaimTypes.NameIdentifier);

Here is a list of all the different claims这是所有不同声明的列表

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

相关问题 如何加载具有 Sitefinity 的测试登录 - Azure AD B2C 身份验证 oauth2 与 JMeter - How to load test login having Sitefinity - Azure AD B2C Authentication oauth2 with JMeter 是否可以使用 Azure AD B2C 以编程方式登录用户? - Is it possible to programmatically log in a user with Azure AD B2C? 将Web表单数据提交到MySQL数据库表时,如何获取登录的Azure B2C用户ID? - How to obtain signed in Azure B2C user’s id when submitting web form data to MySQL database table? Azure AD B2C:无需用户登录即可从ASP.NET Web App调用ASP.NET Web API - Azure AD B2C: Call an ASP.NET Web API from an ASP.NET Web App without user login 将应用程序推送到Azure服务时,Azure AD B2C登录无法正常工作 - Azure AD B2C login not working when app is pushed to Azure service 渐进式 ASP Web 应用程序中的多个 Azure AD B2C 登录屏幕 - Multiple Azure AD B2C login screens in progressive ASP web app 如何从 azure b2c 登录中获取唯一的 session Id - how to get unique session Id from azure b2c sign-in 无法使Web应用重定向到Azure AD B2C登录页面 - Cannot get web app to redirect to Azure AD B2C Sign in Page 用户使用 OAuth2 登录后如何访问或获取 Providerkey - How to access or get Providerkey after user login using OAuth2 Azure AD B2C-多个子域 - Azure AD B2C - Multiple sub domains
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM