graphClient.Users.Request().GetAsync() does not return email if user created by Azure signup process.

Andrey Kuznetsov 65 Reputation points


If I use GraphQL SDK to create B2C users and populate the email field, then it saves fine in GraphQL. But if I use B2C Signup and Singin policy and a user inserts their email in the Azure web form, and verifies it with security code (all things are good here) then on the Azure edit user web page the email field is empty. The email becomes "User Principal Name" and when I get this user's info with GraphQL SDK I have: 1. Mail field is empty. 2. Id field is something like 134ac20f-37fd-4e13-84f8-d8cb307add5a. 3. UserPrincipalName is equals to ID (134ac20f-37fd-4e13-84f8-d8cb307add5a). 4. I've checked the entire IGraphServiceUsersCollectionPage returned object and it has no email/Mail in it.

My question is how to get an email address from GraphQL with SDK using c# and .Net Core7?


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,565 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jeff Mangiafesto 15 Reputation points

    seems like the user profiles aren't being created 'properly' (or at least with all the data you thought was being added) in AD, MS graph can only select data that exists in the active directory pages
    your comment "then on the Azure edit user web page the email field is empty" - shows that the creation of the user was completed successfully but does not contain the mail data you are expecting.
    You'll need to modify the creation of the users (and fix the existing users) to include that data before MS graph can pull it since it can only speak to active directory.
    You can then grab the user object in AD using the SDK and view the user object in debug mode to know what you need to pull out which looks like this:

    var graphClient = new GraphServiceClient(requestAdapter);
    var result = await graphClient.Users["{user-id}"].GetAsync();

    you can read further on the response here:
    but it sounds like you've gotten that far
    I suggest posting the graphQL code that's creating the user itself if you need help getting it into AD, but until you see the data in AD's edit pages - all you're going to get out of the Graph API response is the AD user ID GUID that's auto generated on user creation (components 2 and 3 mentioned in your question)

    0 comments No comments