Build and publish Azure AD B2C custom policies
This extension contains two Azure Pipelines tasks:
- Build Azure AD B2C policies
- Publish Azure AD B2C policies
The build task expects the settings format used with the
Azure AD B2C Visual Studio Code extension.
An example appsettings.json file could look like this:
The policy XML files (located in the same folder) can utilize placeholders that are replaced by the build task:
Usage example in YAML:
- task: b2c-policy-build@1
displayName: Build policies
Three parameters are required:
- environment: a valid environment name from appsettings.json
- inputFolder: the folder that contains the policy XML files and the appsettings.json file
- outputFolder: the folder where the resulting policies are put into (will be created if does not exist)
The fourth parameter
additionalArguments, is optional.
It allows you to override settings in appsettings.json, or add ones that are missing from there.
You could for example use pipeline variables.
There is an example above of its usage; you specify one setting per line in the format
The publish task takes policy XML files that are ready to publish and uploads them to your Azure AD B2C tenant.
It looks at the policies' base policies to publish the base policies first before the policies that require them.
To publish policies, you need to first create an app registration in the Azure AD B2C tenant.
- Login to Azure Portal, ensure you are in the Azure AD B2C tenant
- Open the Azure AD B2C settings blade (you can search for Azure AD B2C in the search bar)
- Go to App registrations
- Click New registration
- Enter any name you want
- Select Accounts in this organizational directory only as the supported account type
- You do not need a redirect URI and you don't need to grant openid or offline_access scope
- Click Register
- Copy the Application (client) ID and the Directory (tenant) ID, they are needed for the publish task
- Go to Certificates & secrets, and add a new client secret. Copy it somewhere as well, it is needed for the publish
- Go to API permissions
- Click Add a permission
- Select Microsoft Graph
- Select Application permissions
- Find Policy.ReadWrite.TrustFramework and select it
- Click Add permissions
- Finally, click Grant admin consent for...
The app registration is now ready, and you should have the tenant id, client id and client secret.
Usage example in YAML:
- task: b2c-policy-publish@1
displayName: Publish policies
Four parameters are required:
- inputFolder: the folder where ready to publish policy XML files are located in (I've used the outputFolder from the build task here)
- authority: identifies the B2C tenant; this will be passed to MSAL.js as the authority setting, usually this would be
- clientId: the client id from the app registration
- clientSecret: the client secret from the app registration (I recommend using a variable set as secret for this at least)