简体   繁体   中英

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:

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?

The id_token property of the authentication response is set to an encoded JSON Web Token (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.

The way I went about this is within my api controller I did the following:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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