Creating Azure B2C Tenant via REST API fails with 401: "You do not have permission to view this directory or page"

Cedric 21 Reputation points
2021-07-19T12:02:22.627+00:00

Hi,

we want to automate the setup of our AAD B2C Tenant as far as we can, therefore we want to leverage the REST API as described here: https://learn.microsoft.com/en-us/rest/api/activedirectory/b2c-tenants/create

For now the API calls are made using Postman, an access token is obtained.
With the documentation above, I can list and read existing B2C tenants, but when we attempt to create a new tenant we fail and receive an HTTP 401 response with the message "You do not have permission to view this directory or page.".

The API calls are executed using a service principal which also is an "Owner" of the subscription.
I can't figure out which permissions I must grant on our service principal in order to succeed.

Creating the B2C tenant via the Azure Portal works just fine.

I would appreciate any comments which point me into the right direction.
Thanks!

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,892 questions
0 comments No comments
{count} votes

Accepted answer
  1. JamesTran-MSFT 36,631 Reputation points Microsoft Employee
    2021-07-20T00:09:55.56+00:00

    @Cedric
    Thank you for your post!

    Based off the documentation, it looks like you'll need to use the OAuth2 implicit Flow with the user_impersonation scope in order to use the REST API. I was able to test out another REST API - Get Secret where that specific API's security section wasn't present in the documentation, and was able to run it without issues.

    116063-image.png

    Can you try using Postman's Authorization flow to see if this helps resolve your issue?
    116018-image.png

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.


0 additional answers

Sort by: Most helpful

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.