如何获取Azure AD tenant的tenant Id?

      一般情况下,Azure AD用户知道自己tenant域名,因为域名是账户的后缀,例如:contoso.onMicrosoft.com。如果你还不了解什么是Azure AD tenant,可以参考What is Azure AD tenant?。那么如何由tenant域名得到用户的tenant id呢?(注意这是tenant id而不是user id)这是在实际工作中经常遇到的问题,特别是在调用API和提供帮助服务,经常需要tenant id。 其实,Azure提供了Powershell (Restful API)和UI两种方式帮助你获取查找 tenant id。
 

Restful API或者Powershell

https://login.windows.net/[YOURDIRECTORYNAME].onmicrosoft.com/.well-known/openid-configuration。例如:https://login.windows.net/contoso.onmicrosoft.com/.well-known/openid-configuration 返回的信息中包含了contoso的tenant id。其实,直接访问上面的URL也可以得到tenant id,下面的Powershell在这里只是帮助你快速找到返回信息中的tenant id。

(Invoke-WebRequesthttps://login.windows.net/[YOURDIRECTORYNAME].onmicrosoft.com/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split('/')[3]

 

Azure Portal

Azure Portal的Azure Active Directory扩展中也可以直接找到tenant id.

 

Azure China

        上面提供查询tenant id 方法是针对Azure全球云服务(https://www.azure.com)。Azure China (https://www.azure.cn)则是部署在中国境内由世纪互联运维的、单独的Azure云服务,其很多操作与Azure全球云服务小有不同,可以参见中国区 Azure 应用程序开发说明。例如, 上面针对tenant id查询,其登陆地址需要改为login.chinacloudapp.cn:
posted on 2018-02-01 10:38  DavidZang  阅读(3111)  评论(0编辑  收藏  举报