{"id":20145033,"url":"https://github.com/michalswi/azure-b2c","last_synced_at":"2025-04-09T19:17:54.142Z","repository":{"id":46722643,"uuid":"363114002","full_name":"michalswi/azure-b2c","owner":"michalswi","description":"Deploy Azure B2C tenant","archived":false,"fork":false,"pushed_at":"2021-09-28T13:01:19.000Z","size":34,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T19:17:46.639Z","etag":null,"topics":["azure","azureactivedirectory","b2c","rest","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michalswi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-30T11:04:12.000Z","updated_at":"2022-02-02T21:33:47.000Z","dependencies_parsed_at":"2022-08-27T23:53:27.717Z","dependency_job_id":null,"html_url":"https://github.com/michalswi/azure-b2c","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalswi%2Fazure-b2c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalswi%2Fazure-b2c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalswi%2Fazure-b2c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michalswi%2Fazure-b2c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michalswi","download_url":"https://codeload.github.com/michalswi/azure-b2c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094988,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","azureactivedirectory","b2c","rest","terraform"],"created_at":"2024-11-13T22:13:41.313Z","updated_at":"2025-04-09T19:17:54.104Z","avatar_url":"https://github.com/michalswi.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Azure B2C tenant**\n\nB2C docs to interact with API available [here](https://docs.microsoft.com/en-us/rest/api/activedirectory/b2ctenants) .  \n\n\n### \\# **PRECONDITION**\n\nTo create new B2C tenant you have to use your private user or functional user registered in Azure Active Directory. It **can't** be a Service Principal.\n\n```\n## check if DOMAIN is free\n\n\n# using 'az rest'\n\naz login\n\nSUBS=`az account show --query \"id\" -o tsv`\n\n$ az rest --method post --url https://management.azure.com/subscriptions/$SUBS/providers/Microsoft.AzureActiveDirectory/checkNameAvailability?api-version=2019-01-01-preview --body @check.json\n{\n  \"message\": null,\n  \"nameAvailable\": true,\n  \"reason\": null\n}\n\n\n# using 'curl'\n\naz login\n\nTOKEN=`az account get-access-token --query accessToken --output tsv`\n\ncurl -i -X POST \\\n-H \"Authorization: Bearer ${TOKEN}\" \\\n-H \"Content-Type: application/json\" \\\n-d @check.json \\\nhttps://management.azure.com/subscriptions/$SUBS/providers/Microsoft.AzureActiveDirectory/checkNameAvailability?api-version=2019-01-01-preview\n\n```\n\n### \\# **DEPLOYMENT**\n\nOnce you know that domain is free you can deploy B2C tenant either using `az rest` or using `terraform` with `az rest` .\n\n### \\# **az rest**\n\n```\naz login\n\nSUBS=`az account show --query \"id\" -o tsv` \\\nRG=demob2c \\\nDOMAIN=b2cdemo1xyz \\\nLOCATION=westeurope\n\naz group create --name $RG --location $LOCATION\n\n\n# deploy\n\naz rest --method put --url https://management.azure.com/subscriptions/$SUBS/resourceGroups/$RG/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$DOMAIN.onmicrosoft.com?api-version=2019-01-01-preview --body @b2c.json --verbose\n\n\n# get\n\naz account tenant list\n\naz rest --method get --url https://management.azure.com/subscriptions/$SUBS/resourceGroups/$RG/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$DOMAIN.onmicrosoft.com?api-version=2019-01-01-preview | jq\n\n\n# delete\n\naz rest --method delete --url https://management.azure.com/subscriptions/$SUBS/resourceGroups/$RG/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$DOMAIN.onmicrosoft.com?api-version=2019-01-01-preview --verbose\n\n\u003e verify if B2C tenant was removed then remove the Resource Group\n\naz group delete --name $RG\n```\n\n\n### \\# **terraform**\n\nIt's really up you how do you want to pass vars. This is just an example.\n\n```\naz login\n\nRG=demob2c \\\nDOMAIN=b2cdemo1xyz \\\nLOCATION=westeurope\n\nterraform init\nterraform plan -var domain=$DOMAIN -var rg=$RG -var location=$LOCATION -out=out.plan\nterraform apply out.plan\n```\nIf completed succesfully, after some time you should see a new tenant. Go to Azure portal or check using az-cli:  \n`portal/Azure Active Directory/Overview/Manage tenants`  \n\n![b2c_create](./img/created_b2c.png)\n\n```\n# check\n\nSUBS=`az account show --query \"id\" -o tsv`\n\naz account tenant list\n\naz resource show --ids /subscriptions/$SUBS/resourceGroups/$RG/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$DOMAIN.onmicrosoft.com\n\n\n# delete\n\nterraform destroy -var domain=$DOMAIN -var rg=$RG -var location=$LOCATION\nrm -rf out.plan .terraform* terraform.*\n```\n\n### \\# **IMPROVEMENTS**\n\n### **delete**\n\nif you switch to a new tenant in Azure Portal, `az rest --method delete` won't work, instead to remove you have to do it either manually or automate it - you will get a checklist with preconditions to be done to allow removal (try, you will see)\n\n### **python library**\n\nthere is available python package `azure-mgmt-azureadb2c` for b2c, you can find more details [here](https://docs.microsoft.com/en-us/python/api/azure-mgmt-azureadb2c/azure.mgmt.azureadb2c.v2019_01_01_preview.operations.b2ctenantsoperations?view=azure-python-preview)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichalswi%2Fazure-b2c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichalswi%2Fazure-b2c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichalswi%2Fazure-b2c/lists"}