How to look up a user by personal email address?

Sam Wheat 361 Reputation points
2020-08-12T23:33:43.547+00:00

I asked this queston on Stackoverflow and also here and I have not yet received an answer. I hope this is the right place to ask:

This question was also posted on StackOverflow.

I actually have two questions which may possibly be related:

Question 1: Why does user personal email address appear in Azure portal as User Principal Name?

Question 2: How do I look up a user by their personal email address?

The email address I will be looking for is the one used as a sign in name so I expect that it should appear in a property like signInNames as is mentioned below.

Steps to reproduce:

Log into Azure portal, Look at a random user and observe their User Principal Name.
Note it appears in the format of a personal email address (joe@somedomain.com). Copy the users Object ID.

In code, create a new GraphServiceClient and retrive the user by object ID using the Object ID copied in the step above.

GraphServiceClient client = GetGraphServiceClient();
User user = await client.Users[userID].Request().GetAsync();

In the User object that is returned, note the value of UserPrincipalName is not what is shown in Azure portal as noted in the first step. It is instead an assigned identifier: cpim_96fe-48b5-88a2-9ac960a6bdab@mydomain.onmicrosoft.com.

Attempt to find a user using personal email address See also:

GraphServiceClient client = GetGraphServiceClient();
IGraphServiceUsersCollectionPage users = await client.Users.Request().Filter("userPrincipalName eq 'joe@somedomain.com'").GetAsync(); // Count = 0
IGraphServiceUsersCollectionPage users = await client.Users.Request().Filter("mail eq 'joe@somedomain.com'").GetAsync(); // Count = 0

As recommended by this answer, this does not work either:

IGraphServiceUsersCollectionPage users3 = await client.Users.Request().Filter("signInNames/any(x:x/value eq 'joe@somedomain.com')").GetAsync(); // error Filter not supported.

My Azure Application has User.ReadWrite.All permission. Personal email address does not appear as any property value for any object I retrieve.

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,669 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,733 questions
0 comments No comments
{count} votes

Accepted answer
  1. AmanpreetSingh-MSFT 56,316 Reputation points
    2020-08-13T07:44:34.2+00:00

    Hello @Sam Wheat

    For some Identity providers, personal email address is populated as Sign-in name and for some IDPs personal email is populated in otherMails attribute. For example:

    • Users signed up for local account in B2C have their email address populated as Sign-in name.
    • Users signed up via Facebook account in B2C have their email address populated as Alternate Email (otherMails attribute) and not as Sign-in name.

    17346-image.png

    Below are the Graph Calls that you can use to find a user by using his/her email address in both cases:

    • To search users when email address is populated as Alternate Email:
      17310-image.png
    • To search users when email address is populated as Sign-in Name:
      17286-image.png

    Note: When filtering on the Sign-in name (identities property), you must supply both issuer and issuerAssignedId.

    Apologies for sharing the graph calls as images. Due to some syntax I was being blocked from posting this answer.

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful