我的问题是:不使用powershell命令可以获得azure活动目录租户id吗?
我找到了这两个博客,有了这个帮助,我已经能够从powershell获得租户ID和订阅ID。这是找回房客的唯一方法吗?
在Windows PowerShell中获取Windows Azure活动目录租户ID
Windows Azure AD认证支持PowerShell
谢谢
我的问题是:不使用powershell命令可以获得azure活动目录租户id吗?
我找到了这两个博客,有了这个帮助,我已经能够从powershell获得租户ID和订阅ID。这是找回房客的唯一方法吗?
在Windows PowerShell中获取Windows Azure活动目录租户ID
Windows Azure AD认证支持PowerShell
谢谢
访问https://login.windows.net/YOURDIRECTORYNAME.onmicrosoft.com/.well-known/openid-configuration,您将看到一堆包含租户ID的url。
当您浏览给定的Active Directory实例时,租户id也会出现在管理控制台URL中,例如:
https://manage.windowsazure.com/<morestuffhere>/ActiveDirectoryExtension/Directory/BD848865-BE84-4134-91C6-B415927B3AB1
通过PowerShell匿名:
(Invoke-WebRequest https://login.windows.net/YOURDIRECTORYNAME.onmicrosoft.com/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split('/')[3]
在Azure CLI中(我使用GNU/Linux):
$ azure login # add "-e AzureChinaCloud" if you're using Azure China
这将要求您通过https://aka.ms/devicelogin或https://aka.ms/deviceloginchina登录
$ azure account show
info: Executing command account show
data: Name : BizSpark Plus
data: ID : aZZZZZZZ-YYYY-HHHH-GGGG-abcdef569123
data: State : Enabled
data: Tenant ID : 0XXXXXXX-YYYY-HHHH-GGGG-123456789123
data: Is Default : true
data: Environment : AzureCloud
data: Has Certificate : No
data: Has Access Token : Yes
data: User name : nico@XXXXXXX.onmicrosoft.com
data:
info: account show command OK
或者仅仅是:
azure account show --json | jq -r '.[0].tenantId'
或者新的az:
az account show --subscription a... | jq -r '.tenantId'
az account list | jq -r '.[].tenantId'
我希望这对你们有帮助
从Java:
public static String GetSubscriptionTenantId (String subscriptionId) throws ClientProtocolException, IOException
{
String tenantId = null;
String url = "https://management.azure.com/subscriptions/" + subscriptionId + "?api-version=2016-01-01";
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
Header[] headers = response.getAllHeaders();
for (Header header : headers)
{
if (header.getName().equals("WWW-Authenticate"))
{
// split by '"' to get the URL, split the URL by '/' to get the ID
tenantId = header.getValue().split("\"")[1].split("/")[3];
}
}
return tenantId;
}
时间会改变一切。我最近也想做同样的事情,然后想到了这个:
Note
添加02/17/2021
稳定的门户页面感谢Palec
添加12/18/2017
正如shadowbq所指出的,DirectoryId和TenantId都等同于表示ActiveDirectory租户的GUID。根据上下文的不同,这两个术语都可能被Microsoft文档和产品使用,这可能会令人困惑。
假设
您可以访问Azure传送门
解决方案
租户ID绑定到Azure中的ActiveDirectoy
导航到仪表板 导航到ActiveDirectory 导航到管理/属性 复制“目录ID”
Azure ActiveDirectory租户ID:
您可以运行一个简单的curl调用来获得azure订阅的租户id,而无需任何身份验证。
做一个卷曲调用:
https://management.azure.com/subscriptions/{订阅id} ? api版本= 2015-01-01
请求失败,但您将能够从响应报头中获得租户id。租户id出现在一行中,后面跟着“WWW-Authenticate: holder authorization_uri="https://login.windows.net/"
您可以使用curl -v来显示响应头。
PowerShell:
Add-AzureRmAccount #if not already logged in
Get-AzureRmSubscription -SubscriptionName <SubscriptionName> | Select-Object -Property TenantId
微软表示:
找到你的tenantID:你的tenantID可以通过打开以下metadata.xml文档来发现:https://login.microsoft.com/GraphDir1.onmicrosoft.com/FederationMetadata/2007-06/FederationMetadata.xml -用你租户的域值替换"graphDir1.onMicrosoft.com"(租户拥有的任何域都可以)。tenantId是一个guid,它是sts URL的一部分,在第一个xml节点的sts URL(“EntityDescriptor”)中返回:“https://sts.windows.net/”。
参考:
https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-graphapi-web/
只是为一个老问题(但仍然相关的问题)添加一个新方法。 在新的门户中,在任何屏幕上单击帮助图标并选择“显示诊断”将显示一个JSON文档,其中包含所有租户信息,包括TenantId、租户名称以及更多有用的信息
我的团队真的厌倦了为我们的O365和Azure项目寻找租户ID。开发人员、支持团队、销售团队,每个人都在某个时候需要它,但从来不记得该怎么做。
所以我们建立了这个小网站,与whatismyip.com相同。希望对你有用!
如何找到我的Microsoft 365、Azure或SharePoint在线租户ID?
以下答案来自微软网站,最后更新日期为2018年3月21日:
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal
简而言之,以下是攻略的截图:
选择Azure Active Directory。
要获取租户ID,请为Azure AD租户选择Properties。
复制目录ID。这个值是您的租户ID。
希望这能有所帮助。
截至目前(06/07/2018),一个简单的方法是在Azure门户中运行Azure云Shell中的az帐户显示(需要存储帐户)。
——命令——
az account show
——命令输出——
{
"environmentName": "AzureCloud",
"id": "{Subscription Id (GUID)}",
"isDefault": true,
"name": "{Subscription Name}",
"state": "Enabled",
"tenantId": "{Tenant Id (GUID)}",
"user": {
"cloudShellID": true,
"name": "{User email}",
"type": "user"
}
}
有关Azure Cloud Shell的更多详细信息,请参阅Azure Cloud Shell | Microsoft Docs概述。
xxx@Azure:~$ az ad sp create-for-rbac
Retrying role assignment creation: 1/36
{
"appId": "401143c2-95ef-4792-9900-23e07f7801e7",
"displayName": "azure-cli-2018-07-10-20-31-57",
"name": "http://azure-cli-2018-07-10-20-31-57",
"password": "a0471d14-9300-4177-ab08-5c45adb3476b",
"tenant": "e569f29e-b008-4cea-b6f0-48fa8532d64a"
}
获取tenantID的简单方法是:
Connect-MsolService -cred $LiveCred #sign in to tenant
(Get-MSOLCompanyInformation).objectid.guid #get tenantID
For AAD-B2C it is fairly simple. From Azure Portal with a B2C directory associated, go to your B2C directory (I added the "Azure AD B2C" to my portal's left menu). In the B2C directory click on "User flows (policies) directory menu item. In the policies pane click on one of your policies you previously added to select it. It should open a pane for the policy. Click "Properties". In the next pane is a section, "Token compatibility settings" which has a property "Issuer". Your AAD-B2C tenant GUID is contained in the URL.
如果您已经在您的机器中安装了Azure CLI 2.0,那么您应该能够使用以下命令获得您所属的订阅列表:
az login
如果你想看到一个表输出,你可以使用
az account get-access-token --query tenant --output tsv
或者你可以使用Rest API
租户-列表|微软文档
一键回答:
打开这个URL:
https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Properties
为我工作的是这个(az登录后):
az account show |grep tenantId | awk {'print $2'} |tr -d '[:punct:]'
使用Azure门户:
步骤1:登录azure门户,搜索azure Active Directory并选择它。 Step2:在Azure Active Directory的概览页面中,找到租户ID。
使用Azure CLI:
使用命令az login、az account list或az account tenant list。在每个命令的输出中为每个订阅查找TenantId属性。
使用Powershell
在powershell cmdlet中使用以下命令。
Connect-AzAccount
Get-AzTenant
参考:
Azure CLI
Get-Aztenant