创建多租户azure AD应用程序的服务主体,以在不同的AAD租户中公开其权限

时间:2017-01-31 21:48:02

标签: openid azure-active-directory multi-tenant openid-connect adal

我在Azure AD中创建了一个应用程序,并翻转了多租户开关,使该应用程序成为多租户。

然后,我按照文章How to sign in any Azure Active Directory (AD) user using the multi-tenant application pattern中列出的步骤从其他Azure AD租户登录到我的多租户应用程序。

代码如下所示

string aadInstance = "https://login.microsoftonline.com/{0}";
string tenant = "common";
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);

Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authority);

AuthenticationResult result = await context.AcquireTokenAsync("https://XXXX.onmicrosoft.com/TodoListServiceMT", AppIdOfAppInDifferentTenant, new Uri("https://localhost:44399/"), new PlatformParameters(PromptBehavior.Always));

但在身份验证期间,我一直遇到以下错误。

  

AADSTS65005:客户端应用程序已请求访问资源   'https://XXXX.onmicrosoft.com/TodoListServiceMT'。这个要求有   失败,因为客户端未在其中指定此资源   requiredResourceAccess list

该错误的修复程序要求我在其他Azure AD租户的客户端应用程序中为我的多租户应用添加权限。

但我无法在其他Azure AD租户中的客户端应用程序的配置权限屏幕中找到我的多租户应用程序。我在该列表中看到的只是Azure AD Graph,ARM和Azure Active Directory。

之前有没有人成功尝试过此方法?在其他Azure AD租户中公开我的多租户应用程序需要做些什么?

此处工作的租户,应用和资源的基本概要..

Tenant A 
  -> Multi-tenant App, resource id(App Id URI)-"https://XXXX.onmicrosoft.com/TodoListServiceMT"

Tenant B
  -> Client App (AppIdOfAppInDifferentTenant)

对于身份验证,我在租户B中使用管理员用户

我尝试将 AppIdOfAppInDifferentTenant 添加到多租户应用的应用清单的 knownclientapplications 部分,但只能在同一租户中添加应用ID应用。

解决方案

  

我仍然不知道为什么我的代码无法生成同意   提示成功注册SP,但我尝试使用相同的   新发布的Azure Active Directory V2 PowerShell Module   它对我有用。

     

在中创建多租户应用程序的SP的命令顺序   不同的租户如下..

Connect-AzureAD -TenantId "TenantId as Guid"
New-AzureADServicePrincipal -AppId "Client/Application Id of the multi tenant application"
  

命令成功完成后,多租户应用程序将会   开始显示在客户端的“必需权限”屏幕中   应用

2 个答案:

答案 0 :(得分:1)

一般来说,您可以尝试使用租户2中的帐户,在租户1中登录您的应用程序,成功登录后,您的应用程序将自动添加到租户2中。您可以尝试按照以下步骤操作:

  1. 在AD应用的配置刀片中启用 MULTI-TENANT enter image description here

  2. 使用adal时修改配置,将tenantId设置为common

  3. 运行您的应用程序,使用租户2中的用户登录您的应用程序。 enter image description here
    接受您在租户1中的申请的许可同意 enter image description here

  4. 成功登录后,您可以在租户2中找到您的应用程序 enter image description here

答案 1 :(得分:0)

Gary Liu的回答大多是正确的,并概述了如何在租户B中创建服务主体。完成后,您应该能够:

  1. 转到新门户网站
  2. 应用注册
  3. 下找到您的客户端应用
  4. 转到所需权限
  5. 点击添加
  6. 点击选择API
  7. 在显示的搜索栏中输入多租户应用或其中一部分的名称
  8. 选择多租户应用,然后定义客户端需要的权限