Search code examples
flutterazureazure-active-directorybearer-token

flutter User.Read azure active directory "Insufficient privileges to complete the operation"


I am trying to get the data of a signed in user using Microsoft graph API. I work with the "aad_oauth" package in flutter. When signing in, an access token is provided. This access token is then used in a http.get request.

However every time I try to get the data, the following error appears. "{"error":{"code":"Authorization_RequestDenied","message":"Insufficient privileges to complete the operation:"

I also added a permission at the ad admin center. enter image description here

That's how I get the access token enter image description here

This is my http request enter image description here


Solution

  • I tried to reproduce the same in my environment and got the below results:

    I created an Azure AD application and added user.read permission:

    enter image description here

    Now I generated access token via Postman with below parameters:

    GET https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
    grant_type:authorization_code
    
    
    
    client_id:1b323717-80d8-4172-b141-XXXXXX
    client_secret:GTT8Q~PErY3nTbj9LO8Nkkm2ai.XXXXXXX
    scope:user.read
    code:code
    redirect_uri: redirect_uri
    

    enter image description here

    To get the details of the signed-in user, I ran the below query by including bearer token:

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

    enter image description here