简体   繁体   中英

Microsoft Graph API get groups for user gives privileges error

Requirement : We would like to query the groups of a user via Microsoft's Graph API with the following request:

https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_getmembergroups

In our case the response looks like this:

{
  "error": {
    "code": "Authorization_RequestDenied",
    "message": "Insufficient privileges to complete the operation.",
    "innerError": {
      "request-id": "a230a67e-8ef1-4f88-aa19-2c5b983c3de4",
      "date": "2017-01-04T16:29:55"
    }
  }
}

(Note: the GET https://graph.microsoft.com/v1.0/me/ is working fine and returns the user data)

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
  "id": "e23976a1-8bd9-4cca-a410-e095d2c2022d",
  "businessPhones": [],
  "displayName": "XXXX Vad",
  "givenName": "XXXX",
  "jobTitle": null,
  "mail": null,
  "mobilePhone": null,
  "officeLocation": null,
  "preferredLanguage": null,
  "surname": "Vad",
  "userPrincipalName": "XXXX.vad_outlook.com#EXT#@XXXXvadoutlook.onmicrosoft.com"
}

Environment:

  • Application created on apps.dev.microsoft.com with the following parameters: o Application Id: 412386c3-8fa3-4000-9039-748111407XXX o Delegated Permissions: [ User.Read ]
  • This application is visible on 'Azure Portal / AAD / Enterprise applications' and the user with a group 'BASIC' is added to this application

An example of an access token obtained from AAD:

{
  "aud": "https://graph.microsoft.com",
  "iss": "https://sts.windows.net/b9df6a2d-9150-45f9-abf0-9c30f9e527c7/",
  "iat": 1483548390,
  "nbf": 1483548390,
  "exp": 1483552290,
  "acr": "1",
  "aio": "AQABAAEAAADRNYRQ3dhRSrm-4K-adpCJhEVX2WEl4aboghl6AXaqOVcbaQPl1yYg1X1D2r4cNxBYmPvUiTKE9bB6wwpNSBKeD2OZXhrzdE3FPddCzbaTo84X8aSoKFaAt2vysYSv1HdChNXBPbfrVlA6YBuSwVwEIAA",
  "altsecid": "1:live.com:00037FFEC5917401",
  "amr": [
    "pwd"
  ],
  "app_displayname": "XXX test",
  "appid": "412386c3-8fa3-4000-9039-748111407XXX",
  "appidacr": "0",
  "email": "XXXX.vad@outlook.com",
  "family_name": "Vad",
  "given_name": "XXXX",
  "idp": "live.com",
  "ipaddr": "165.225.80.95",
  "name": "XXXX Vad",
  "oid": "e23976a1-8bd9-4cca-a410-e095d2c20XXX",
  "platf": "3",
  "puid": "10037FFE9D51DXXX",
  "scp": "User.Read",
  "sub": "sCDfsIUynhm4GdgPIe8hYguyNbbc7IBjZeKLd1UDXXX",
  "tid": "b9df6a2d-9150-45f9-abf0-9c30f9e52XXX",
  "unique_name": "live.com#XXXX.vad@outlook.com",
  "ver": "1.0"
}

What am I doing wrong or what's missing? Any help is appreciated.

You have to have admin consent right now to pull groups. They changed the required permissions a while back.

https://blogs.msdn.microsoft.com/aadgraphteam/2015/03/18/update-to-graph-api-consent-permissions/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM