让我们来看看吧!
我有一个租户:shawntest.onmicrosoft.com
我使用 Azure 门户在此租户中创建了一个新的访客用户:
我点击了“+新来宾用户”按钮,并创建了您可以在上面看到的来宾 Gmail 帐户。我还将此用户添加到了几个组中,也在门户中:
让我们让这个用户登录。
首先,在这些情况下,指定要让用户登录的租户很重要。您可能不应该对这些类型的帐户使用common 端点,因为它们可能与多个租户相关联,并且然后您将其留给 AAD 为您做出最终决定。相反,使用特定的租户 id 指定特定的身份验证上下文:
https://login.microsoftonline.com/shawntest.onmicrosoft.com
现在使用您首选的用户登录流程获取令牌。我正在使用 Native Client 流程,可以使用 just 13 lines of PowerShell 轻松模拟。
获得令牌后,我会调用/me 端点以显示我正在与外部用户合作的证据:
GET https://graph.windows.net/me?api-version=1.6
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element",
"odata.type": "Microsoft.DirectoryServices.User",
"objectType": "User",
...
"displayName": "Shawn Tabrizi",
...
"userPrincipalName": "xxxxxx_gmail.com#EXT#@shawntest.onmicrosoft.com",
"userType": "Guest"
}
我觉得不错。现在让我们使用memberOf 查询来获取用户所属的组。请注意,您可以立即执行此查询,它不依赖于上次查询的任何数据。
GET https://graph.windows.net/me/memberOf?api-version=1.6
{
"odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects",
"value": [{
"odata.type": "Microsoft.DirectoryServices.Group",
"objectType": "Group",
...
"displayName": "TestGroup",
...
"securityEnabled": true
}, {
"odata.type": "Microsoft.DirectoryServices.Group",
"objectType": "Group",
...
"displayName": "MyTestGroup",
...
"securityEnabled": true
}]
}
这就是所有人!