Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get an OID claim in ASPCore from Azure B2C

Why do I want this?

I'm trying to get a unique identifier from my user which I can connect to database records. There are reasons I don't want to use the Email as the identifier. I read that SUB claim isn't supported with B2C, and to use OID in it's place.

Steps I've Taken

So, I've set up that both of my policies return Object ID on Azure B2C:

enter image description here

I'm using individual SignIn and SignUp policies at the moment, and I get all of the claims back, including the email claim which I specified I wanted to be returned. I cannot however find a claim related to OID or SUB.

User.Claims 

Nets me the following results:

enter image description here

The single breadcrumb of hope that I have found is this claim:

Type: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier

Value: Not supported currently. Use oid claim.

Questions

Have I missed some additional step that you need to perform to retrieve this particular claim?

Has anyone had any success retrieving an OID or SUB from Azure B2C?

like image 613
David Moores Avatar asked Aug 16 '16 15:08

David Moores


2 Answers

I struggled with this for a little while and this post helped me.

To update things with some code, the below will obtain the object identifier value (unique user id in Azure)

User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value

Thanks for pointing out the differences in the schema/types!

like image 77
Coy Meeks Avatar answered Nov 27 '22 14:11

Coy Meeks


Well, this is embarrassing, I must have looked over this line about 30 times and not noticed...

I was retrieving the OID token, it's claim type was:

http://schemas.microsoft.com/identity/claims/objectidentifier

As can be clearly seen in my provided screenshots. I'll leave this question up as, the schema may throw someone else off.

like image 21
David Moores Avatar answered Nov 27 '22 14:11

David Moores