Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,854 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Im using
var scopes = new[] { "https://graph.microsoft.com/.default" };
var clientSecretCredential = new ClientSecretCredential(tenantId, appId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
how to change it to get the user email?thx
Hello @Miguel , in order to get the user email for an Azure AD B2C consumer user account you can do use the following .NET code. It will display the emailAddress
used for sign-in (local accounts) or the first otherMails
address (for federated accounts).
var clientSecretCredential = new ClientSecretCredential(tenantId, appId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var result = await graphClient.Users["id"].GetAsync(c => c.QueryParameters.Select = new[] { "identities" });
Console.WriteLine(result?.Identities?.Find(o => o.SignInType == "emailAddress")?.IssuerAssignedId ?? result?.OtherMails?.FirstOrDefault());
Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.