1

I have an ASP.NET Core application with work & school account authentication as configured by Visual Studio 2015 Update 3. I'm trying to integrate Microsoft.Graph with my application. Specifically, I'm trying to obtain user information (name, department, mail, about me, etc.) from the currently logged in user.

Following the samples for previous versions of ASP.NET MVC, I managed to make the following code work.

var token = await GetAppTokenAsync(authStringMicrosoft, graphResourceId); var authHelper = new AuthenticationHelper() { AccessToken = token }; var graphClient = new GraphServiceClient(authHelper); var users1 = await graphClient.Users.Request().GetAsync(); var users2 = await graphClient.Users.Request().Select("mail,givenName,surname").GetAsync(); 

This code is placed on the OnTokenValidated callback of OpenIdConnectEvents within OpenIdConnectOptions, on my Startup class.

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { // ... Events = new OpenIdConnectEvents { OnTokenValidated = async ctx => { // right here } } }); 

So far, both calls to Users work great, and the code retrieves me a list of users with the specified properties. However, whenever I try to get data from the Me property, I get an error, as described below.

User me = await graphClient.Me.Request().GetAsync(); 

Error:

Code: Request_ResourceNotFound Message: Resource '65c4885a-b493-4b8d-861f-79f0b8c23ec4' does not exist or one of its queried reference-property objects are not present. Inner error 

I don't get why am I getting this error. I have checked the permissions for the application in the Azure Management Portal, both for Windows Azure Active Directory and Microsoft Graph applications. As a test, I checked everything that is to check, and still get this error.

So, my question is: why I get this error? Do I need to add a different permission, do I need to include anything else?

Thank you in advance.

1 Answer 1

1

From the sample code, it looks like app token is used here. /me request is not valid in context where app token (obtained by client_credential flow) is used. It is valid only in the context of access token obtained by authorization code flow (also referred to as 3-legged flow). If you can share request-id header from the error response along with timestamp, I can confirm.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Sriram, thank you for your response. Let me get the info you suggested and I'll get back to you. But, if I understand you correctly, for the client_credential flow I'd have to search for the specific user, is that correct?
Thank you Sriram, you were correct. I was using app token authentication. I managed to get user info by querying directly into the Users builder.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.