How to get the azure account tenant Id?

后端 未结 21 1299
故里飘歌
故里飘歌 2020-11-30 17:47

My question is: Is it possible to get the azure active directory tenant id without using powershell command?

I found this two blogs and with this help, I\'m already

相关标签:
21条回答
  • 2020-11-30 18:17

    According to Microsoft:

    Find your tenantID: Your tenantId can be discovered by opening the following metadata.xml document: https://login.microsoft.com/GraphDir1.onmicrosoft.com/FederationMetadata/2007-06/FederationMetadata.xml - replace "graphDir1.onMicrosoft.com", with your tenant's domain value (any domain that is owned by the tenant will work). The tenantId is a guid, that is part of the sts URL, returned in the first xml node's sts url ("EntityDescriptor"): e.g. "https://sts.windows.net/".

    Reference:

    https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-graphapi-web/

    0 讨论(0)
  • 2020-11-30 18:23

    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.

    0 讨论(0)
  • 2020-11-30 18:24

    The tenant id is also present in the management console URL when you browse to the given Active Directory instance, e.g.,

    https://manage.windowsazure.com/<morestuffhere>/ActiveDirectoryExtension/Directory/BD848865-BE84-4134-91C6-B415927B3AB1
    

    Azure Mgmt Console Active Directory

    0 讨论(0)
  • 2020-11-30 18:25

    As of now (06/07/2018), an easy approach would be running az account show in the Azure Cloud Shell (requires a Storage Account) in the Azure Portal.

    --- Command ---

    az account show
    

    --- Command Output ---

    {
      "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"
      }
    }
    

    Find more details on Azure Cloud Shell at https://docs.microsoft.com/en-us/azure/cloud-shell/overview.

    0 讨论(0)
  • 2020-11-30 18:26

    From 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;
    }
    
    0 讨论(0)
  • 2020-11-30 18:26

    You can also get the tenant id, in fact all subscription details by logging into the url resources.azure.com

    0 讨论(0)
提交回复
热议问题