Postman - Microsoft Graph beta/tenantRelationships/托管租户/租户 - UnknownError 401 未经授权

问题描述 投票:0回答:1

我正在尝试编写一个自动化程序,读取所有托管租户、他们的用户以及他们正在积极使用的所有许可证。我遇到的问题之一是通过邮递员获取信息。

我有一个具有全局管理员权限的单独同步帐户。如果我登录 Graph Explorer,同意 ManagedTenants.Read.All 并查询 https://graph.microsoft.com/beta/tenantRelationships/managedTenants/tenants 它可以工作并返回数据。

如果我在 Postman 中做同样的事情,我会得到: enter image description here

在 Postman 中,我在应用程序中使用授权代码和 Postman 回调 url 设置。我使用与 Graph Explorer 相同的帐户登录,但仍然收到未经授权的错误。 enter image description here

在整个组织的应用程序中授予管理员同意。

azure microsoft-graph-api
1个回答
0
投票

创建了一个 Microsoft Entra ID 应用程序并授予 API 权限,如下所示:

enter image description here

我使用授权代码流程生成了访问令牌

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
grant_type:authorization_code
code:code
redirect_uri:https://jwt.ms
client_secret:ClientSecret
scope:https://graph.microsoft.com/.default

enter image description here

或者,您可以使用以下 API 来获取客户 ID:

enter image description here

注意:要读取其他租户的用户信息,该用户必须是该租户的一部分。

TenantB
中,邀请
TenantA
用户:

enter image description here

TenantA
用户必须接受邀请:

enter image description here

创建 Microsoft Entra ID 并分配

User.Read.All
委派权限:

enter image description here

使用

TenantA
用户登录以生成访问令牌。

生成访问令牌:

https://login.microsoftonline.com/TenantBTenantID/oauth2/v2.0/token

client_id:TenantBAppID
grant_type:authorization_code
scope:https://graph.microsoft.com/.default
code:code
redirect_uri:https://jwt.ms
client_secret:ClientSecret

enter image description here

现在通过使用上面的访问令牌,

TenantA
可以从
TenantB

检索用户信息

enter image description here

参考资料:

azure - 是否可以从租户 A 为租户 B 创建用户 (Microsoft Entra ID)? - Stack Overflow 由我

列出合约 - Microsoft Graph v1.0 |微软

© www.soinside.com 2019 - 2024. All rights reserved.