Azure JWT具有属性“hasgroups = true”而不是groups属性对象

时间:2017-08-04 08:14:00

标签: azure-web-sites azure-active-directory

我有一个Azure Web应用程序,使用Azure Active Directory身份验证(使用adal-angular制作);

在应用程序清单中,我设置了"groupMembershipClaims": "SecurityGroup"

奇怪的是,在某些日子里,对于一个用户来说,它在AAD令牌中没有组声明,其中包含组成员身份objectIds的列表,而是有一个名为hasgroups的属性,其值为{ {1}}。

我能为此做些什么吗? 现在我要检查是否有一个属性或另一个属性,然后调用GraphAPI直接成为组成员。

2 个答案:

答案 0 :(得分:6)

如果用户属于“太多群组”,则返回

hasGroups=true我不知道确切的阈值是多少( 20?200?)但实际上你需要在你的代码中做的是(伪代码):

if (hasGroups)
  Call the Graph to inquire:
    Either about the full group membership OR 
    About membership to a particular group
else
  Access groups directly from the token

Get all the groups a users belongs to

https://graph.windows.net/myorganization/users/{user_id}/$links/memberOf?api-version

Inquire whether the user belongs to a specific group

https://graph.windows.net/myorganization/users/{user_id}/isMemberOf?api-version

答案 1 :(得分:0)

请检查您使用的是Authorization Code grant还是implicit grant

hasGroups 声明仅在implicit_grant的情况下提供,并且 groups 声明中提供的组数限制为6个,以便扩展URI片段超出网址长度限制。请参阅Azure Active Directory access tokens中的 hasGroups groups 声明文档。