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