Azure AD B2C - Get user id

Al Mus 6 Reputation points
2022-09-01T08:41:21.757+00:00

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?

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,662 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Marilee Turscak-MSFT 34,306 Reputation points Microsoft Employee
    2022-09-02T19:39:00.923+00:00

    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("http://schemas.microsoft.com/identity/claims/objectidentifier").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: https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/4-WebApp-your-API/4-2-B2C/TodoListService/Controllers/TodoListController.cs

    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
    2022-09-09T06:09:13.237+00:00

    @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
    2022-10-28T01:48:01.4+00:00

    @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