Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Azure tenant name from graph.microsoft.com?

I need to discover user's tenant name, since the service endpoint, resourceId that I'll be using an Azure service that requires me to specify the tenant name:

service endpoint: https://[tenantnamme].api.crm.dynamics.com/...
resource Id: https://[tenantname].crm.dynamics.com

I was hoping Unified Microsoft Graph API can discover this for me. I looked at the documentation, the closest I can see is to use graph.microsoft.com/v1.0/organization which will give me back: verifiedDomains : [ .... "name" : "contoso.onmicrosoft.com" ]

But, I'm not sure if this is the right approach. What if an org has multiple verified domains? Does verified domain name is the same as tenant name?

Update: This is my real scenario. I have a web app that allows user to authenticate to Azure AD via OAuth2. I have no problem obtaining refresh token and access token from OAuth interactions. However, in other to use other service, it requires [azure-ad-tenant-name] in their service end point. That's my question coming from.

like image 875
Andy H. Avatar asked Apr 06 '16 20:04

Andy H.


People also ask

How do I get Azure tenant name?

To find a tenant ID and a primary domain name:Sign in to the Azure portal. Select Azure Active Directory from the menu. The Azure Active Directory Overview page appears. To find the Azure AD tenant ID or primary domain name, look for Tenant ID and Primary domain in the Basic information section.

What is tenant ID in graph API?

An immutable, non-reusable identifier that identifies the directory tenant that issued the token. You can use this value to access tenant-specific directory resources in a multi-tenant application. For example, you can use this value to identify the tenant in a call to the Graph API.


1 Answers

I believe that you're on the right track with the graph.microsoft.com/v1.0/organization endpoint. You should be able to find the tenant name in the verifiedDomains list. The entry that should contain domain with the tenant name is the initial domain:

{
    ...
    "isInitial": true,
    "name": "contoso.onmicrosoft.com",
    ...
}
like image 132
shtrule Avatar answered Oct 15 '22 21:10

shtrule