I have a azure AD secured web API which I am authenticating using bearer token. The app registration on azure AD and all has been done. I am able to access secured API using bearer token and getting the expected response.
The problem I am facing is I have no clue how to get user info where i can have the organisation name to which user belongs to. I came to know that there is Microsoft Graph API where I can get this details but to access that I need to create another bearer token and than only can access and get the details from MS graph API. I want to access the graph api using same bearer token because I don't want my server to re-authenticate and ask for user credentials. Is this possible?
code I am using to get the access token is :
AuthenticationContext authContext = new AuthenticationContext(
"https://login.microsoftonline.com/<My Tenant Id>");
AuthenticationResult token = authContext.AcquireTokenAsync(<secured web
api resource id>,<clientId Id>, new Uri(redirectUri),new
PlatformParameters(PromptBehavior.Always)).Result;
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue(token.AccessTokenType, token.AccessToken);
HttpResponseMessage httpResponse = client.GetAsync("Secured Web API
call").Result;
This works well.
After few lines of code, When trying to access Microsoft graph API, it give No Authorised error code.
Grpah API url : "https://graph.microsoft.com/v1.0/organization
Any help would be highly appreciated.