Data from Microsoft Entra to Web Page

MOUSSAOUI Mohammed 40 Reputation points
2024-08-21T15:44:05.6466667+00:00

Hello,

I created an application on Microsoft Entra and granted it the necessary permissions. I would like to display users on a web page with their first name, last name, email addresses, etc.

Capture d’écran de la table Autorisations configurées après l’octroi du consentement administrateur

I have all the access of the application (access token, tenant id...)User's image

I'd like to have a display like this (like the contacts in Sharepoint) on my Web Page if it's possible.

User's image

Could you please tell me how I can do that?

Thank you

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
975 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,941 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.
2,847 questions
Microsoft Entra
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,420 questions
{count} votes

Accepted answer
  1. James Hamil 24,386 Reputation points Microsoft Employee
    2024-08-27T20:21:10.3666667+00:00

    Hi @MOUSSAOUI Mohammed , have you used the Graph API? It's a good way to accomplish this. You can follow the linked document for detailed instructions, but the following is a sample code snippet:

    
    // Initialize the MSAL library
    const msalConfig = {
      auth: {
        clientId: 'YOUR_CLIENT_ID',
        authority: 'https://login.microsoftonline.com/YOUR_TENANT_ID',
        redirectUri: 'http://localhost:3000'
      }
    };
    const msalInstance = new msal.PublicClientApplication(msalConfig);
    
    // Authenticate the user and obtain an access token
    const loginRequest = {
      scopes: ['User.Read.All']
    };
    msalInstance.loginPopup(loginRequest).then(response => {
      const accessToken = response.accessToken;
    
      // Call the Microsoft Graph API to retrieve a list of users
      const usersEndpoint = 'https://graph.microsoft.com/v1.0/users';
      const usersRequest = new Request(usersEndpoint, {
        headers: new Headers({
          'Authorization': `Bearer ${accessToken}`
        })
      });
      fetch(usersRequest).then(response => {
        return response.json();
      }).then(data => {
        // Parse the JSON response and display the user data on your web page
        const users = data.value;
        users.forEach(user => {
          const firstName = user.givenName;
          const lastName = user.surname;
          const email = user.mail;
          // Display the user data on your web page using HTML and JavaScript
        });
    

    Please let me know if you have any questions and I can help you further.

    If this answer helps you please mark "Accept Answer" so other users can reference it.

    Thank you,

    James

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

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.