Reputation: 101
What I need to do is to calling Microsoft graph from C# Web API. This is basically what my method looks like:
var clientCredential = new ClientCredential(clientId, clientSecret);
AuthenticationContext context = new AuthenticationContext(authority);
AuthenticationResult authenticationResult = context.AcquireToken(clientId, clientCredential);
if (authenticationResult == null)
{
throw new InvalidOperationException("Failed to obtain the token");
}
return authenticationResult;
what i receive by this call is:
then my idea is to call microsoft graph passing this token (and i'm not even 100% sure that this is the correct way of implementing the implicit flow)...but after that i receive the "invalid token" error.
could anyone tell me where i'm doing wrong here? Thank you alot!
Upvotes: 0
Views: 634
Reputation: 58723
Your problem is the way you acquire the token.
This should be:
context.AcquireToken("https://graph.microsoft.com", clientCredential);
The first parameter is the resource URI for the API you want a token for.
Also this is not implicit flow, it is client credentials flow where the app accesses an API as itself, using application permissions.
Upvotes: 1