在 Microsoft Dynamics 365 中使用 Web API 连接两个租户时出错:用户不是组织的成员

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

我正在尝试在属于不同 Azure 帐户的两个租户之间建立连接。

我关注了帖子:https://stackoverflow.com/a/78437433/4373243

我的目标是利用租户 B 的 Web API,但使用租户 A 的客户端 ID 和客户端密钥。但是,我目前正在使用与租户 B 关联的tenant_id,以及租户的范围(Web API 端点) B.

租户 B Web api 端点:https://org8885b353.api.crm.dynamics.com/

$response = $this->client->post("https://login.microsoftonline.com/{tenantB_id}/oauth2/v2.0/token", [
'timeout' => 30,
'form_params' => [
'client_id' => 'tenantA_clientId',
'client_secret' => 'tenantA_clientSecret',
'scope' => 'https://org8885b353.api.crm.dynamics.com/.default',
'grant_type' => 'client_credentials',
],
]);

当我调用下面的 URL 以从 $response 获取具有访问令牌的所有实体的列表时,它会抛出一个错误:

https://org8885b353.api.crm.dynamics.com/api/data/v9.2
"error": {
"code": "0x80072560",
"message": "The user is not a member of the organization."
}

下面是api权限截图 enter image description here

azure oauth-2.0 multi-tenant webapi
1个回答
0
投票

如果未通过在 Power Platform 管理中心添加 Microsoft Entra ID 应用程序的 Application ID 创建应用程序用户,通常会出现错误

“用户不是组织的成员”

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

enter image description here

TenantB
中,应用程序被添加为企业应用程序,如下所示:

enter image description here

使用如下参数生成访问令牌

GET https://login.microsoftonline.com/TenantBID/oauth2/token

client_id:TenantAAppID
client_secret:TenantASecret
scope: https://orgxxxxxx.crm.dynamics.com
grant_type:client_credentials

enter image description here

并得到同样的错误

GET 
https://orgXXX.api.crm.dynamics.com/api/data/v9.2

enter image description here

要解决该错误, 通过添加 Microsoft Entra ID 应用程序的

Application ID
创建*应用程序用户。

转到 Power Platform 管理中心 -> 环境 -> 选择您的组织 -> 设置 -> 用户 + 权限 -> 选择应用程序用户

enter image description here

点击新建应用程序用户 -> 添加应用程序 -> 使用应用程序 ID 搜索应用程序 -> 添加

enter image description here

Business Unit
下,选择您的组织并分配 系统管理员 角色,然后选择创建:

enter image description here

再次重新生成访问令牌,我能够成功获得响应,如下所示:

GET 
https://orgXXX.api.crm.dynamics.com/api/data/v9.2

enter image description here

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