【问题标题】:How to find out the tenant name using REST API如何使用 REST API 找出租户名称
【发布时间】:2018-12-14 03:57:13
【问题描述】:
【问题讨论】:
标签:
azure
azure-active-directory
azure-management-api
azure-management
【解决方案1】:
AFAIK,如果你想使用 rest api 来做到这一点,似乎我们可以只使用 MS 图 api :Get organization 或 AAD 图 GET https://graph.windows.net/{tenant id}/tenantDetails?api-version=1.6 来获取租户名称,但它只是获取当前经过身份验证的租户.
如果您想通过资源获取租户名称,您可以使用 azure powershell 来执行此操作。如您所知,请具体说明资源所在的-SubscriptionId 。
$TenantId = (Get-AzureRmSubscription -SubscriptionId "xxxx").TenantId
Connect-AzureAD -TenantId $TenantId
Get-AzureADTenantDetail
DisplayName 是租户名称。
【解决方案2】:
主要端点是https://graph.microsoft.com/v1.0/organization
示例代码(Node.js):
const info_tenant = await apiRequestFunction(`https://graph.microsoft.com/v1.0/organization`, 'GET', null, {
"Authorization": access_token,
"Content-Type": "application/json"
});
返回组织信息,其中info_tenant.value[0].displayName 是租户名称。