简体   繁体   中英

MS Graph and Azure Active Directory

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" 在此处输入图像描述

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. 在此处输入图像描述

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. 在此处输入图像描述

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

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

在此处输入图像描述

  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.

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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM