Active Directory B2C authentication and making/storing user IDs in a DB
authentication, azure, azure-ad-b2c, azure-sql-database
Solution
In the auth token you receive back from Azure AD, you have an object ID that is unique to each user.
The B2C token is slightly different to the regular AD token, you don't get back all the values listed in the Token Reference (e.g. Groups, you have to query for these separately), but you will get the object ID that you can then use to lookup your DB.
https://azure.microsoft.com/en-gb/documentation/articles/active-directory-token-and-claims/
You can decode your JWT token here to see what you get back: https://jwt.io/
Problem
I'm making a mobile app and want to use the AD B2C stuff to handle authentication for my users. I need to store data for them in a SQL DB which will also be on Azure. I intended to have my app use REST to communicate with some Functions I was going to write to then talk to the DB back end which would query various things specific to that user. My problem is I'm not sure how to map a user who has been authenticated with the authentication system to some unique ID or index in my DB. Is there some way that I can safely identify a newly registered or logged in user such that I can create a way of identifying them? I say safe because I don't want to commit a faux pas and use some value from the auth library that would be considered a security risk or bad practice. Thanks.