Azure AD B2C - Get user id

Al Mus 6 Reputation points

I am making a TODO app, and I have a list of Tasks, and a list of Users.
I add user_id to the Task, and when the User logs in, I only want them to see the Tasks assigned to them.

How do I do this with Azure AD B2C? This is not about authorities.

Do I need to keep two lists of users, one internal and one on Azure, and then make a mapping between them?

Azure Active Directory External Identities
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Marilee Turscak-MSFT 27,561 Reputation points Microsoft Employee

    Hi @Al Mus ,

    The 'oid' (object id) is the only claim that should be used to uniquely identify a user in an Azure AD tenant, as it cannot get reassigned.

    There is a B2C sample here that shows how to assign tasks to B2C users by object ID and create a "to-do" list that only allows users to see their own tasks.

    You would identify the task owner by the user's object ID and ensure that the object ID is added as an application claim in all of your policies.

    // Controllers\TasksController.cs  
    public IEnumerable<Models.Task> Get()  
     string owner = ClaimsPrincipal.Current.FindFirst("").Value;  
     IEnumerable<Models.Task> userTasks = db.Tasks.Where(t => t.owner == owner);  
     return userTasks;  

    There is another sample here that you can use for reference:

    See also:
    Mapping oid
    External users, user_id, and object ID

    Let me know if this is what you are looking for.


    If the information helped you, please Accept the answer. This will help us and other community members as well.

    0 comments No comments

  2. Al Mus 6 Reputation points

    @Marilee Turscak-MSFT , thanks for the answer.

    In my user table, I'm also keeping additional information, such as availability, skills and similar.

    I assume I cannot keep that information in Azure B2C.

    Do I have to keep two lists of users with some kind of a mapping between a User and oid?

    0 comments No comments

  3. Al Mus 6 Reputation points

    @Marilee Turscak-MSFT , when I create a user in Azure B2C, can I also give a custom property?
    I want to assign one field that will be matched to my database

    0 comments No comments