Get Office 365 Tenant ID from Domain Name

OpenID Connect describes a metadata document that contains most of the information required for an app to do sign-in. This includes information such as the authorization endpoint, token endpoint, tenant region scope, etc. For the discovery endpoint, this is the OpenID Connect metadata document you should use:

https://login.windows.net/{domain}/.well-known/openid-configuration

The {domain} can take one of two values:

Value Description
common Users with both a personal Microsoft account and a work or school account from Azure AD can sign in to the application.
contoso.com The friendly domain name of the Office 365 tenant

The metadata is a simple JSON. See the following snippet for an example.

Screen Shot 2019-06-16 at 7.04.26 PM.png

To get the tenant ID, we just need to parse the token_endpoint property as shown below:

Screen Shot 2019-06-16 at 6.50.58 PM

We will get the following JSON for the invalid domain name.

Screen Shot 2019-06-16 at 7.13.44 PM.png

Hope this helps. Sharing is Caring !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.