Search code examples
graphazure-active-directoryazure-ad-b2c

Retrieve Azure AD B2C UserPrincipaleName with MS Graph API


On my Azure AD B2C tenant I have the following user.

It is created without a name and without a mail. Only UserPrincipaleName has a value set at creation time.

enter image description here

I try to collect that UserPrincipaleName using microsoft graph API : https://graph.microsoft.com/v1.0/users

For some reason, the UserPrincipaleName I'm collecting doesn't have the same value and is rather made of the object id and the domain name.

    {
        "businessPhones": [],
        "displayName": "unknown",
        "givenName": null,
        "jobTitle": null,
        "mail": null,
        "mobilePhone": null,
        "officeLocation": null,
        "preferredLanguage": null,
        "surname": null,
        "userPrincipalName": "[email protected]",
        "id": "12345678-abcd-efgh-12345678910a"
    }

How can I retrieve the [email protected] value using msgraph API ?


Solution

  • I find out that identities object had the information I was looking for :

            "identities": [
                {
                    "signInType": "emailAddress",
                    "issuer": "mydomain.onmicrosoft.com",
                    "issuerAssignedId": "[email protected]"
                },
                {
                    "signInType": "userPrincipalName",
                    "issuer": "mydomain.onmicrosoft.com",
                    "issuerAssignedId": "[email protected]"
                }
            ]