I have an Azure based application that requires a bunch of Azure resources (app services + plans, SQL servers, storage accounts, and an Azure AD B2C instance) per instance of the application.
So I am making a tool that automatically generates a new instance of this application (i.e. it creates each of these resources programmatically using my C# .NET 7 web application), and I have been able to programmatically create everything with the Azure SDK for .NET except for the Azure AD B2C instance.
My goal is to:
- Create an Azure AD B2C tenant
- Create an App Registration within it
- Create a couple of user flows within it
I do see there is a AD B2C REST API, which I could manually tap into for #1. Is this the only way? And are #2 and #3 even possible?
2
Answers
I’m not sure using c# SDK, but you can do it using Pulumi:
https://www.pulumi.com/registry/packages/azure-native/api-docs/azureactivedirectory/b2ctenant/
Or you can also use c# and interact directly with REST API:
https://learn.microsoft.com/en-us/rest/api/activedirectory/b2c-tenants/create?tabs=HTTP
Yes, you can create an Azure Active Directory B2C instance programmatically using C# and the latest Azure.ResourceManager nuget package (previousaly know as Azure Management), but my question is: Why did you want to create a B2C tenant for each type of Azure service? I hope you are aware of the pros and cons of having the subscription in another tenant and the AD apps in another tenant.
If your goal is only to authenticate and authorise the Azure services with Azure AD, then you can create the app registrations for Azure services in the same tenant where your Azure subscription resides instead of creating a new B2C tenant.(depend on your use case)
The following the Azure Sample repo on Azure B2C Tenant managment using C#
App Registration
You can use the graph API or client SDK to manage the entire lifecycle of the app registration process. The following is the Microsoft Graph API Explorer, which you can directly test from Web Explorer or import in Postman and then use in a C# application.
https://developer.microsoft.com/en-us/graph/graph-explorer
This explorer also provides sample code in C# and other languages to implement APIs in your application. It is located in the Explorer’s section below.
I hope this will help you automate your work. Let me know if you require any other details.