.net azure function get user

Nerin Peter Chetty (For Azure) 86 Reputation points
2022-12-12T14:48:51.08+00:00

Hi ,
i tried getting user from azure ad b2c through azure function in .net web api but i am getting the following error

System.Private.CoreLib: Exception while executing function: GetUsers. Azure.Identity: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

i followed following document https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS

why i am not able to get token from azure kindly help me if i am missing something

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,695 questions
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.
3,252 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
25,011 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,366 Reputation points
    2022-12-13T09:24:56.36+00:00

    Hi @Nerin Peter Chetty (For Azure)

    I can't reproduce your problem, please refer to my code, it can perfectly lists all users in the Azure AD B2C tenant.

    Frameworks:

    270024-image.png

    Dependent packages:

    269989-image.png

    using Azure.Identity;   
    using Microsoft.Graph;  
    using Newtonsoft.Json;  
      
    var scopes = new[] { "https://graph.microsoft.com/.default" };  
      
    var tenantId = "the tenant ID of the B2C tenant";  
      
    // Values from app registration  
    var clientId = "client id";  
    var clientSecret = "client secret";  
      
    // using Azure.Identity;  
    var options = new TokenCredentialOptions  
    {  
        AuthorityHost = AzureAuthorityHosts.AzurePublicCloud  
    };  
      
    // https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential  
    var clientSecretCredential = new ClientSecretCredential(  
        tenantId, clientId, clientSecret, options);  
      
    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);  
      
    var users = await graphClient.Users  
          .Request()  
          .GetAsync();  
      
    Console.WriteLine("users:" + JsonConvert.SerializeObject(users));  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Nerin Peter Chetty (For Azure) 86 Reputation points
    2022-12-15T08:52:35.533+00:00

    Thank you its working i am able to get user

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.