oauth-2.0 – AAD组声称某些用户在JWT令牌中丢失

我在AAD上遇到了一些奇怪的行为.用户登录成功后,我们的API调用会对某些用户进行未经授权的操作.事实证明,JWT中的索赔缺失.有些用户正在获得“组”声明(他所属的所有groupIds的数组),有些用户正在获得“hasgroups”声明(如果用户有组,则没有ID,则为布尔值).由于我们的API应用程序正在检查此“群组”授权声明,因此没有此“群组”声明的用户将获得403.

然而,在应用程序注册的清单中,我将“groupMembershipClaims”从“null”设置为“All”或“SecurityGroup”,这应该同时执行这两个操作.当我们使用使用OAuth2的Angular应用程序时,还要将“oauth2AllowImplicitFlow”设置为true.接下来我比较了几乎所有的用户设置,除了一些额外的组,用户是相同的.受影响的用户没有很多组,有些甚至在最多的5组.

我是否忽视了某些内容或者是什么导致了索赔中的这种差异?我如何解决这个问题,以便所有用户都获得“群组”声明?

最佳答案 得到了MSFT内部的反馈:

In the implicit flow, oauth will return the Jwt directly from the
intial /authorize call through a query string param. The http spec
limits the length of a query string / url, so if AAD detects that the
resulting URI would be exceeding this length, they replace the groups
with the hasGroups claim.

还有这个

This is by design when using implicit grant flow, regardless the
“groupMembershipClaims” setting in the manifest. It’s to avoid to go
over the URL length limit of the browser as the token is returned as a
URI fragment. So, more or less after 4 user’s groups membership,
you’ll get “hasgroups:true” in the token. What you can do is to make a
separate call to the Graph API to query for the user’s group
membership.

因此,需要对Graph API进行额外的往返才能获得用户组.希望这也有助于其他人.

点赞