restazure-ad-b2cadalazure-sdk-.netazure-oauth

How can I ensure a domain name isn't already taken before creating Azure B2C tenant?


I'm in the process of setting up Azure AD B2C tenants, but I keep encountering a roadblock. Whenever I try to use a specific domain name, it tells me it's "Already in use by another directory." However, I'm uncertain if that's accurate. Is there a way to check if a domain name is available before I proceed to create a B2C tenant?

I need to create multiple directories, so it's crucial for me to confirm that the domain name I intend to use is available before initiating the setup process. Can someone guide me on how to check if a domain name is free for Azure AD B2C before I attempt to create a tenant?


Solution

  • To check whether the B2C domain name is available or not, you can make use of this Azure Management API call.

    Initially, I generated access token to call Azure Management API by running below CLI command:

    az account get-access-token --resource=https://management.azure.com --query accessToken --output tsv
    

    Response:

    enter image description here

    Now, I used that token to call Management API and got below response when domain name is not available:

    POST https://management.azure.com/subscriptions/subId/providers/Microsoft.AzureActiveDirectory/checkNameAvailability?api-version=2021-04-01
    
    {
      "name": "srib2c.onmicrosoft.com",
      "countryCode": "US"
    }
    

    Response:

    enter image description here

    You will get below response when Azure AD B2C domain name is available:

    POST https://management.azure.com/subscriptions/subId/providers/Microsoft.AzureActiveDirectory/checkNameAvailability?api-version=2021-04-01
    
    {
      "name": "sridemob2c.onmicrosoft.com",
      "countryCode": "US"
    }
    

    Response:

    enter image description here