我们的应用程序允许为组分配权限,这意味着对于每个用户,我们必须可靠地确定组成员身份。用户提供使用ADAL定期获得的令牌(一些使用.NET,另一些使用NodeJS,其他人使用CLI)。
有些用户似乎在发送带有以下声明的令牌:
"hasgroups": true,
该声明记录在Azure AD token reference页面中。
我们想为此添加一个测试用例,但在执行了here和here之后,我们总是得到一个带有以下声明的令牌:
"_claim_names": {
"groups": "src1"
},
"_claim_sources": {
"src1": {
"endpoint": "https://graph.windows.net/{redacted}/users/{redacted}/getMemberObjects"
}
},
我们的设置有什么问题?为什么我们不能得到hasgroups
索赔?
以下是一些其他信息:
"oauth2AllowImplicitFlow": true
。我们使用以下代码获取令牌(在C#中):
var userCredential = new UserCredential( _userName, _password );
result = context.AcquireToken( _resource, _clientId, userCredential );
哪里:
_userName
和_password
来自有很多团体的用户。_clientId
是本机应用程序的应用程序ID - 与"oauth2AllowImplicitFlow": true
的应用程序ID。_resource
是https://vault.azure.net
。令牌正确发出。唯一的问题是它显示_claim_names
和_claims_sources
而不是hasgroups
。
其中:•_userName和_password来自具有许多组的用户。
由于用户是许多组的一部分(假设这里有6个或更多).Azure AD令牌将返回组中的超量指示符而不是“组”声明中的实际组ID。我想你知道这一点,因此故意这样做。
var userCredential = new UserCredential( _userName, _password ); result = context.AcquireToken( _resource, _clientId, userCredential );
由于您使用C#代码在基于.NET的应用程序中获取令牌,因此令牌响应的长度并不受限制(例如,对于Web SPA,它作为URI片段返回,并且URL长度有限制)
查看文档“hasgroups”和“groups:src1”声明具有相同的意图,即告知有太多组作为令牌的一部分返回。虽然有一个微妙的区别: