skip to Main Content

I have created an Azure B2C custom attribute called IsAdmin on the portal, added it to a Sign In / Sign Up user flow, and then using the Graph API, successfully created a new user with IsAdmin = true. If I then sign in using that new user I can see IsAdmin returned in the token as a claim. So far so good.

However I can’t seem to see that custom attribute when querying via Graph API, nor can I search for it.

    var user = await graphClient.Users["{GUID HERE}"]
        .Request()
        .GetResponseAsync();

The user is returned, but the custom attribute is not present.

    var results = await graphClient.Users
        .Request()
        .Filter("extension_anotherguid_IsAdmin eq true")
        .GetAsync();

Returns no results.

Does anyone have any idea?

2

Answers


  1. Extensions are not returned by default. You need specify the extension in Select

    var user = await graphClient.Users["{GUID HERE}"]
            .Request()
            .Select("extension_anotherguid_IsAdmin")
            .GetResponseAsync();
    

    The value should be available through AdditionalData.

    var extValue = user.AdditionalData["extension_anotherguid_IsAdmin"];
    

    Resources:

    Extensibility

    Login or Signup to reply.
  2. When storing custom attribute in a B2C tenant, a microsoft’s managed app registration is created :

    enter image description here

    Take the app id of this app registration, remove the dashes in the id and then use it like below :

    import requests
    
    # if your app registration b2c extensions app id id is aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee :
    b2c-extensions-app-id-without-dashes="aaaaaaaabbbbccccddddeeeeeeeeeeee" 
    url = f"https://graph.microsoft.com/v1.0/users/?$select=extension_{b2c-extensions-app-id-without-dashes}_IsAdmin"
            headers = {
            'Content-type': 'application/json',
            'Authorization': 'Bearer ' + msgraph_token
            }
    r = requests.request("GET", url, headers=headers) 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search