Reputation: 347
I have an url from one of my azure app website. What I want to do is to do a Web request on this url by using token.
I managed to retrieve the token $token with the same method as here. And the folowing command worked fine
Invoke-WebRequest "https://graph.microsoft.com/v1.0/me" -Headers @{Authorization="Bearer $token"}
Then I tried
Invoke-RestMethod -Uri "myurl" -Headers @{"authorization" = "Bearer $token"}
But I got the folowing issue :
Invoke-WebRequest : {"code":401,"message":"IDX10511: Signature validation failed. Keys tried: '[PII is hidden]'. \u000akid: '[PII is hidden]'. \u000aExceptions caught:\u000a
'[PII is hidden]'.\u000atoken: '[PII is hidden]'."}
So it seems that the signature is not valid. Any Idea why and how to fix it ? Thanks
Upvotes: 1
Views: 2181
Reputation: 58773
It does not work because the token is for Microsoft Graph API, not your API.
To acquire an access token for your API, add a scope to its app registration (Expose an API tab).
Then when acquiring a token, assign that scope's full value to the scope
query parameter.
This full value will include either the App ID URI or the client ID of the API app registration + the value you define for the scope.
Upvotes: 2