Reputation: 3024
If i have a tenant name such as "contoso.onmicrosoft.com" can i get the tenantID using an API call? I have already checked the API for Microsoft.Azure.Management.ResourceGroup
Upvotes: 3
Views: 6581
Reputation: 668
You can simply call https://login.microsoftonline.com/tenantDomain/.well-known/openid-configuration
and get the tenant id from there. Just parse the JSON it returns and get the tenant id from it - for example from issuer
.
Full info can be found here.
The call doesn't have to be authenticated so it is very simple to call.
Upvotes: 6
Reputation: 3293
Te easiest way to get tenantID is to find it in Azure portal. Please click -> APPLICATION -> VIEW ENDPOINT. like the following screenshot:
If you want to use C# to get the tenant ID from the name. Please try to get the JWT token first (use the user under the "contoso.onmicrosoft.com" to sign in). The JWT token will contain tid. "tid" means tenant id. Refer to this article for more details. Then we can use the following code to get the tenant id:
var token = new JwtSecurityToken(jwtToken);
var oid = token.Claims.FirstOrDefault(m=>m.Type == "tid").Value;
Upvotes: 0
Reputation: 12228
You can get the name of the tenant you are logged into by calling
https://management.azure.com/tenants?$skiptoken={skiptoken}&api-version={api-version}
see here for details This will give you a list of all tenants that you authorized for.
This is actually listed under 'Tenants' rather than resource groups.
Upvotes: 4