can you guide me how to access same token just like https://developer.microsoft.com/en-us/graph/graph-explorer

Anonymous
2023-09-10T14:03:27.4466667+00:00

how to access same token just like https://developer.microsoft.com/en-us/graph/graph-explorer for my site

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Authenticator
Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2023-09-11T13:03:59.5233333+00:00

    Hi @Anonymous ,

    Thanks for reaching out.

    To access the same token as the Graph Explorer, you need to register your application in the Azure portal and configure it to use the Microsoft identity platform for authentication. Once you have registered your application, you can use the Microsoft Authentication Library (MSAL) to acquire an access token for the Microsoft Graph API.

    Here are the high-level steps to follow:

    1. Register your application in the Azure portal and configure it to use the Microsoft identity platform for authentication by assigning appropriate permissions.
    2. Add the Microsoft Authentication Library (MSAL) to your application.
    3. Use MSAL to acquire an access token for the Microsoft Graph API.
    4. Use the access token as bearer token to call the Microsoft Graph API.
       GraphServiceClient graphServiceClient = this.GetGraphServiceClient();
            await graphServiceClient.Me
                .SendMail(message, true)
                .Request()
                .WithScopes("Mail.Send").PostAsync();
            return View("MailSent");
    

    Reference: https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/2-WebApp-graph-user/2-1-Call-MSGraph/README.md

    Samples to call Graph API based on app type - https://learn.microsoft.com/en-us/azure/active-directory/develop/sample-v2-code?tabs=apptype

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.


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.