多租户 API - 管理员同意错误 https://login.microsoftonline.com/organizations/v2.0/adminconsent AADSTS90009

Multitenant API - Admin consent ERROR https://login.microsoftonline.com/organizations/v2.0/adminconsent AADSTS90009

使用以下端点充当租户 B 上的管理员我想注册一个多租户 API 在另一个租户 A 中定义的应用程序:

https://login.microsoftonline.com/{tenantB}/v2.0/adminconsent?
client_id={GUIDAppIDInTenantA}
&redirect_uri=http://localhost:8080/myredirecturi
&scope=api://{GUIDAppIDInTenantA}/.default

我收到这个错误:

AADSTS90009 Application is requesting a token for itself. This scenario is supported only if resource is specified using the GUID based App Identifier

我正在使用来自 TenantA 的基于 GUID 的应用标识符。我进入登录页面,登录后,我立即被重定向到 redirect_uri,并出现上述错误。

post 使用不同的端点并提到使用我已经在使用的 GUID

替换

&scope=api://{GUIDAppIDInTenantA}/.default

&scope={GUIDAppIDInTenantA}/.default

首先像这样添加“openid profile”范围
https://login.microsoftonline.com/secondTenandID/v2.0/adminconsent?client_id={APP_IP}&redirect_uri={redirect_URI}&scope=openid+profile

这将注册应用程序(并信任主租户)

其次,使用此格式提交另一个包含实际多租户 API 范围的请求

 https://login.microsoftonline.com/secondTenandID/v2.0/adminconsent?client_id={APP_IP}&redirect_uri={redirect_URI}&scope={APP ID}/.default

这样APP就会在次租户中注册到主租户的全部权限

你只需要 &scope=.default https://login.microsoftonline.com/{ConsentingTid}/v2.0/adminconsent?client_id={WebOrSpaAppId}&redirect_uri={RedirectUri}&scope=.default

无需将应用程序 ID 拼写两次。

如果您所做的只是为您征得同意API,您只需同意一次。

此外,在您的 MSAL2 客户端代码中:

interactionType: InteractionType.Redirect,
      authRequest: {
        scopes: [
          '.default'
        ]
      }