Microsoft Graph API 在查询来宾帐户时出错

时间:2021-03-15 17:05:30

标签: azure azure-active-directory microsoft-graph-api

我正在使用 Microsoft Graph Explorer 来测试一些查询。一种是获取 Azure AD (Azure B2B/B2C) 中来宾用户帐户的列表。

我使用其中一个示例查询:

https://graph.microsoft.com/v1.0/users/?$filter=userType%20eq%20'guest'

针对客户的 Azure AD,我得到所有访客用户的 json 结果。

但是当我对我的 Azure AD 租户运行这个时,我得到了这个:

<块引用>

URI 中指定的查询无效。找不到房源 在类型上命名为“userType” 'Microsoft.Fast.Profile.Web.Models._1._0.Profile'。

我的 Azure AD 租户是“Azure AD Free”许可证类型 - 不确定这是原因还是很重要。我是 Azure AD 租户的全局管理员。

这是由于我的 Azure AD 租户中的其他设置造成的吗?还是因为它是 Azure AD Free 许可证?我可以创建访客帐户。

1 个答案:

答案 0 :(得分:1)

请求的 URL 是正确的。使用 Microsoft Graph Explorer 时,您应该使用会员帐户登录。如果您登录访客帐户,则会返回此错误。

enter image description here

或者您可以根据 Postman 中的应用程序使用 client credential flow。确保您已添加适当的权限。

获取访问令牌:

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token 
Content-Type: application/x-www-form-urlencoded

client_id={client_id}
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret={client_secret}
&grant_type=client_credentials

调用 MS Graph API:

GET https://graph.microsoft.com/v1.0/users/?$filter=userType%20eq%20'guest'
Authorization: Bear <access_token>