0

I am using Graph api https://graph.microsoft.com/v1.0/me to access user email from a different tenant using access token I am getting .

I have used profile and openid scopes but can't use User.read as it will need admin consent for the app.

Any solutions to this ?

4
  • Can u pls include the error response after adding the API permission? Commented Jul 10 at 12:40
  • Are you getting such kind of error message Commented Jul 11 at 5:11
  • Yes @Pratik I am getting that privilege error
    – Rik
    Commented Jul 11 at 5:26
  • You need to have atleast Delegated type User.Read permission to resolve the error. Commented Jul 11 at 5:30

1 Answer 1

1

"error": { "code": "Authorization_RequestDenied", "message": "Insufficient privileges to complete the operation.",

This error occurs if you don't add Delegated type User.Read API permission or missed granting the admin consent to the added permission.

I registered one Multi-tenant Entra ID application and granted API permission like below:

enter image description here

To get code, I ran below authorization request in browser:


https://login.microsoftonline.com/common/oauth2/v2.0/authorize? 
&client_id=<app_id>
&client_secret = <client_secret>
&redirect_uri= https://jwt.ms
&response_type=code  
&response_mode=query  
&scope= https://graph.microsoft.com/.default

When I tried to generate access token with below parameters via Postman, I got same error as below:

POST https://login.microsoftonline.com/common/oauth2/v2.0/token 
client_id=<app_id>
client_secret = <client_secret>
redirect_uri= https://jwt.ms
code=code  
scope= https://graph.microsoft.com/.default

Response:

enter image description here

enter image description here

To resolve the error, add Delegated type User.Read API Permission and grant admin consent :

enter image description here

Now, generated code and access token using same code snippet:

enter image description here

Now, you can call /me enpoint to get mail_id:

GET https://graph.microsoft.com/v1.0/me

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.