I'm experiencing some strange behavior on our AAD. After a user signed in successful, we're getting an unauthorized for some users on our API calls. Turns out that a claim in the JWT is missing. Some users are getting the "groups" claim (array of all groupIds he belongs to) and some are getting the "hasgroups" claim (a boolean if the user has groups, no Ids). As our API app is checking this "groups" claim for authorization, the users who don't have this "groups" claim are getting a 403.
Nevertheless, in the manifest of the app registration I set the “groupMembershipClaims” from “null” to "All" or "SecurityGroup", which should do both the trick. Also set the "oauth2AllowImplicitFlow" to true as we're working with an Angular app which uses OAuth2. Next to that I've compared almost all users settings and apart from some extra groups the users are identical. The affected users don't have a lot of groups, some have even around the 5 groups at max.
Do I overlook something or what's causing this difference in claims? How can I solve this so all users are getting the "groups" claim?
This is now documented in the Azure AD token reference at https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-token-and-claims.
For the OAuth2 implicit grant flow it uses the
hasGroups
token and the documentation states for this token:For other flows:
You can use the Graph API to obtain a user's groups using
https://graph.windows.net/{tenantID}/users/{userID}/getMemberObjects
.Alternatively there is the endpoint at
https://graph.windows.net/myorganization/isMemberOf?api-version
as documented at https://msdn.microsoft.com/library/azure/ad/graph/api/functions-and-actions#isMemberOfGot this feedback from MSFT internals:
And this
So will need to do an extra roundtrip to Graph API in order to get the user groups. Hope this helps others too.