0
votes

Problem: How to authenticate in MS Graph using Azure AAD access token.

Current flow:

My web app has AAD configured with "Log in with AAD" enter image description here

If I log into AAD my demo app is showing and if I go to https://******.azurewebsites.net/.auth/me then I get the access_token. enter image description here

What I tried: So I tried a couple of things and this was the last, I copied the access_token as code and tried to send it, didn't work. enter image description here

I'm searching for a solution to silently use the already logged-in user and call MS Graph.

2

2 Answers

0
votes

For the already logged in user you need follow the below steps for access:

  1. Make sure you have enable the allow access token for the register app as below

enter image description here

  1. Write code to acquire access token for the for the logged in user Reference

  2. Now you can pass this token in other successive call to get the result.

0
votes

The reason for the error is that you have used the wrong code. Don't try to send the access token as a code, you should request an authorization code in your browser.

https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
client_id={client id}
&response_type=code
&redirect_uri={redirect_uri}
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345

In addition, redirect_uri is also a required parameter.

enter image description here