How to get the azure account tenant Id?

后端 未结 21 1455
故里飘歌
故里飘歌 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: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;
    }
    

提交回复
热议问题