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:
- Register your application in the Azure portal and configure it to use the Microsoft identity platform for authentication by assigning appropriate permissions.
- Add the Microsoft Authentication Library (MSAL) to your application.
- Use MSAL to acquire an access token for the Microsoft Graph API.
- 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");
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.