简体   繁体   English

使用多租户应用程序从Azure租户获取订阅

[英]Get Subscriptions from Azure tenant using multi-tenant application

I'm trying to build a multi-tenant application to retrieve all subscription information from my personal account. 我正在尝试构建一个多租户应用程序,以从我的个人帐户中检索所有订阅信息。

Using the Powershell ARM I'm able to retrieve this information: 使用Powershell ARM,我可以检索以下信息:

在此处输入图片说明

However, when trying to do this action using the azure management API: 但是,当尝试使用Azure管理API执行此操作时:

https://management.azure.com/subscriptions?api-version=2016-06-01 https://management.azure.com/subscriptions?api-version=2016-06-01

Using a JWT generated using my tenant, application id and key secret it returns the following: 使用通过我的租户,应用程序ID和密钥机密生成的JWT,它将返回以下内容:

{"value": [] } {“值”:[]}

My application permissions seem fine: 我的应用程序权限看起来不错:

在此处输入图片说明

Am I missing something from my permissions? 我的权限丢失了吗?

Edit: I am able to get my tenants using the same endpoint. 编辑:我能够使我的租户使用相同的端点。 Could this be something to do with my companies permissions for AAD users? 这与我的公司对AAD用户的权限有关吗?

First,you'r using client credentials flow. 首先,您正在使用客户端凭据流。 With this flow, you cannot on behalf a user. 使用此流程,您将无法代表用户。 The Delegated permissions is not for this flow, it's for other on behalf user flow, like code grant flow. 委派权限不适用于此流程,而是其他代表用户的流程,例如代码授予流程。 So,you need to choose which one flow you need to use. 因此,您需要选择需要使用的一种流程。 If you still want to use client crendentials flow, you can take following steps to give it permissions: 如果仍然要使用客户端凭据流,则可以执行以下步骤来为其授予权限:

You need to assign Role to your Service principal via Azure RBAC . 您需要通过Azure RBAC将角色分配给您的服务主体。 Go to Azure portal > Select one specific subscription > Access control(IAM) > Add > choose your service principal > select Contributor role > Save 转到Azure门户>选择一个特定的订阅>访问控制(IAM)>添加>选择服务主体>选择贡献者角色>保存

You can take same steps to add assign role to your sp from other subscription. 您可以采取相同的步骤从其他订阅中向您的sp添加分配角色。

After doing this, you can have enough permissions to use REST API via client credentials flow. 完成此操作后,您将具有足够的权限通过客户端凭据流使用REST API。 在此处输入图片说明

About list subscriptions from other tenants: 关于其他租户的列表订阅:

I didn't test this because I don't have mulitple subscriptions. 我没有对此进行测试,因为我没有多个订阅。 But with multiple tenant APP, it also needs other tenant admin consent and assign role to it too. 但是对于多租户APP,它还需要其他租户管理员的同意并为其分配角色。

With client credetials flow, you still can only get access token for one tenant. 使用客户端凭据流,您仍然仍然只能获得一个租户的访问令牌。 So, you can only list subscriptions from one tenant once. 因此, 您只能列出一位租户的订阅。

Update: 更新:


Even powershell actually gets subscriptions from other tenant from different teannt IDs many times. 甚至powershell实际上也多次从其他租户从不同的id获得订阅。 So, you cannot use API to achieve that directly. 因此,您不能使用API​​直接实现该目标。

I use Fiddler to catch the Traffic with Powershell running Get-azureRMsubscriptions: 我使用Fiddler通过运行Get-azureRM订阅的Powershell来捕获流量:

在此处输入图片说明

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM