There are a large amount of OAuth systems you can connect with for authentication of you website users.
Here are some insights on connecting with Azure B2C. With Custom policies you have the power to adjust your user flows!
By Danny Paul van Iersel, 04-06-2024
In our first part you have read about the Sitecore configuration on how to setup B2C authentication within Sitecore: Sitecore authentication with Azure B2C Custom policies Part 1
Now we will continue on how to configure your B2C custom policies.
The easiest way to get started is to use the provided flows from the B2C like “Sign up and sign in” flow. You can quickly test and see if your connection works.
But if we truly want to accomplish more with our flows we can setup Custom Policies. On the Microsoft learning platform you will find a tutorial how you can get started with custom policies
Within our B2C tenant go to Identity Experience Framework.
Go to Policy Keys:
Policy keys:
App registration:
Start editing your policy:
In your B2C Tenant go to the Identity Experience Framework:
Register your application.
Add a new registration:
From the “Custom policies” you can upload your custom policies that we will create further on.
Custom policies that are created are shown below
When modifying a custom policy that already exist make sure you check the check box “Overwrite the custom policy if it already exists”.
By following the guide at https://learn.microsoft.com/en-us/azure/active-directory-b2c/add-password-reset-policy?pivots=b2c-custom-policy
You will be able to modify the behaviour for the forgot your password flow. By the default flow this will cause a redirect back to your application from where you can start the password reset flow. With custom policies you can enable the flow to stay within the B2C flow and continue without redirecting back to your application.
Modify the following files to accomplish this.
TrusFrameworkBase.xml:
TrustFrameworkExtensions.xml:
SignUpOrSignin.xml:
Add output claim:
With the Sign up flow you sometimes don’t want users to enter their own DisplayName.
If the DisplayName is not provided with the sign up form this will give the behaviour in the User list of your B2C an awkward look. For by default the column Display name is shown and it will show “unknown” for every user. Which makes it a bit difficult to read.
In order to do this we need the following changes to our TrustFrameWorkBase.xml
Scenario:
To check if a provided email should be allowed to create a user.
If you have complex application logic that needs to be implemented you have the possibility to call a Rest API from within the B2C Policy
Assuming we already have an API to call that returns a HTTP 200 OK response if the validation is approved.
If the check is not approved then it should return a HTTP 409 Conflict as response.
To setup the this requirement we need:
You can check all the Metadata, error handling, cryptographic keys, input and output parameters on: https://learn.microsoft.com/en-us/azure/active-directory-b2c/restful-technical-profile
To use our TechnicalProfile we need to add it to the ValidationTechnicalProfile.
In our code of the API if it is approved we send an OK message:
If it is not okay we send out the following message:
Using custom policies with Azure B2C can provide you with a massive variety of possibilities that can make your implementation work extremely well for you.
You can cover almost every aspect of the wishes from your customers and provide them with a solution that fits their needs.
At Blastic we are always happy to help you and you are always free to contact us if you need any assistance.
Ready to take your digital experience to the next level? Feel free to contact us to learn more about our services and how we can help you leverage the full potential of your digital marketing.
Get in touch with one of our consultants to find the perfect match that fits your needs and enables you to grow.