2

我正在构建基于多租户 SaaS Web 的应用程序。应用程序在我的租户中注册,每个拥有 office 365 订阅的客户都将在 Azure AD 中获得服务主体对象。

我在从客户租户的外部帐户(Microsoft 帐户)登录时遇到问题。

我创建了示例并尝试查看我可以从访问令牌中获得什么。

示例由一个使用 MSAL 库处理身份验证的客户端应用程序 (.js) 和两个具有受保护端点的 API 组成。我还创建了三个独立的 Azure AD 应用程序 AlanClient、AlanAPI1、AlanAPI2。AlanAPI1 和 AlanAPI2 都公开了 API(在 Azure 门户应用程序中公开 API 部分)并指定了一个消费者 AlanClient。AlanClient 拥有这两个 API 的权限。所有应用程序都注册了“accessTokenAcceptedVersion”:2 和“signInAudience”:“AzureADMultipleOrgs”。

据我了解,这应该足以登录

  1. 来自宿主租户的 Office 365 帐户
  2. 在宿主租户中注册为外部用户的 Microsoft 帐户
  3. 来宾租户的 Office 365 帐户
  4. 在来宾租户中注册为外部用户的 Microsoft 帐户

说明:-主机租户->注册应用程序的 Azure AD 实例。在租户 A 下方的错误消息中。 - 来宾租户 -> 仅使用应用程序的 Azure AD 实例

我对案例号有疑问。4

我收到此错误消息: AADSTS50020:来自身份提供者“live.com”的用户帐户“lovro.p365@...”在租户“A”中不存在,并且无法访问该租户中的应用程序 AlanClient。需要先将该帐户添加为租户中的外部用户。注销并使用不同的 Azure AD 用户帐户重新登录。

4

1 回答 1

2

2和4的场景应该是一样的。

我已经测试了两者,一切都很好。

您可以使用OAuth 2.0 身份验证代码授权流程对其进行测试。

login.microsoftonline.com使用您的应用配置构建请求。

此 URL 将如下所示:

https://login.microsoftonline.com/[tenant A]/oauth2/v2.0/authorize?client_id=[client id of the Azure AD app registered in host tenant]&response_type=code&redirect_uri=[redirect uri of the Azure AD app]&nonce=1234&resource=https://graph.microsoft.com.

在租户 A 中使用 Microsoft 帐户的凭据登录后,您将在地址栏中获得一个“代码”。使用此代码请求访问令牌:

POST /[tenant]/oauth2/v2.0/token HTTP/1.1

client_id=[client id of the Azure AD app registered in host tenant]
&scope=https://graph.microsoft.com/user.read
&code=[code got from the previous step]
&redirect_uri=[redirect uri of the Azure AD app]
&grant_type=authorization_code

然后,我们可以作为租户 A 中的来宾用户获取 Microsoft 帐户的访问令牌。

于 2019-11-14T02:19:44.757 回答