Can you create an Azure B2C Tenant with a Service Principal?

devopsfj 256 Reputation points
2023-06-05T15:42:37.23+00:00

I am looking to setup an automated pipeline which deploys and configures Azure B2C Tenants in multiple environments.

I am running into a 401 error during the pipeline, I am using Terraform to deploy Azure B2C.

Error: performing Create: unexpected status 401 with error: Unauthenticated: Unauthenticated
│
│ with azurerm_aadb2c_directory.b2c,
│ on azure-ad-b2c.tf line 5, in resource "azurerm_aadb2c_directory" "b2c":
│ 5: resource "azurerm_aadb2c_directory" "b2c" {
│
│ performing Create: unexpected status 401 with error: Unauthenticated:
│ Unauthenticated

I am using a Service Principal to try and create Azure B2C, is this not supported?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,526 Reputation points Moderator
    2023-06-19T18:35:51.1933333+00:00

    Hello @devopsfj , apoligies for any confusion caused by my initial answer. As stated by the SO post shared by @azure enthusiast, creating an Azure B2C tenant with a service principal is not possible by design since we need a user to request the operation in order to assign him as the first global administrator of the new tenant.

    The current workaround for automation purposes is to obtain an access token as a user using the ROPC flow. Also, there's an idea posted in the Azure Feedback Forums that can be upvoted. The more votes it gets the more the product team may consider it for future implementation.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,526 Reputation points Moderator
    2023-06-05T19:47:45.38+00:00

    Hello @devopsfj , you can create an Azure AD B2C tenant using a service principal using Azure REST API. The error encountered suggestd your call is not authenticated. For more information about authentication take a look to the Terraform documentation.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.