0

When you create a ADB2C Tenant Resource, an application registration is also created, named b2c-extensions-app. Do not modify. Used by AADB2C for storing user data. This is a special application which is needed for crud operations.

Around the internet and in the docs, it is mentioned that it gets created automatically, but that's not the case. It is created only after you login into that tenant and go to app registrations, it is a trigger of some sorts. How do I know this? I reached to Microsoft support.

My question: this interferes with some of my automation scripts. Does anyone know of an endpoint to which I can make a rest request so this app gets created.

1 Answer 1

2

Okay, after a lot and I mean a lot of trial and error, I finally found the endpoint that causes the creation of that app. I will show a code snippet in PowerShell.

$context = Connect-AzAccount ...

# Aquire an access token from the resource: https://management.core.windows.net/
$tokenItem = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate(
        $context.Account,
        $context.Environment,
        $TenantId,
        $null,
        'Never',
        $null,
        'https://management.core.windows.net/')

Invoke-WebRequest -Uri "https://main.b2cadmin.ext.azure.com/api/tenants/GetAndInitializeTenantPolicy?tenantId=<your_tenant_name>&skipInitialization=false" `
-Method "GET" `
-Headers @{
   "Authorization"          = "Bearer $($tokenItem.AccessToken)";
   "x-ms-client-request-id" = ([guid]::NewGuid().Guid)
}
9
  • I deleted my answer. But when I tried your solution, it shows Invoke-WebRequest : An error has occurred.Unauthenticated although I have got a valid access token for https://management.core.windows.net/. Can you tell me how you get the token?
    – Allen Wu
    May 28, 2021 at 2:16
  • I use auth code flow in Postman to get the access token. I also tried use $accessToken = (Get-AzAccessToken -ResourceUrl "https://management.core.windows.net/").Token in powershell. Neither of the 2 tokens work.
    – Allen Wu
    May 28, 2021 at 2:18
  • Maybe I missed an add permission operation in app registration? Can you show it? Thanks in advance.
    – Allen Wu
    May 28, 2021 at 2:19
  • 1
    Thank you so much. I successfully creates the b2c extension app. It's cool!
    – Allen Wu
    May 28, 2021 at 8:07
  • 1
    Thanks for this solution! Just to add for those who don't want (or can't) use Azure PowerShell - an alternative method of getting the access token would be with Azure CLI like this: az account get-access-token --tenant $B2CTenantId --query accessToken -o tsv - . Oct 13, 2021 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.