- Install Visual Studio Code
- Install the Azure AD B2C custom policy extension
- Install the Azure Tools extension
- An Azure Subscription - to create the B2C tenant
- Azure Cloud Shell - to execute the scripts that do a lot for you :)
When working with this repository, you will clone within the cloud shell.
mkdir workspace && cd workspace
git clone https://github.com/kevinhillinger/azureadb2c-aspnetcore-sample.git
cd azureadb2c-aspnetcore-sample
Once this is done, you will be able to execute scripts within the ./scripts
folder.
To build this sample with custom policies in B2C, the following things needs to be done:
- Create a B2C tenant and associate it to your subscription
- Create the keys and application registrations in B2C for the Identity Experience Framework (to use the custom policies)
- Create the application registration for extension attributes (custom attributes for users)
- Create an application registration in the B2C tenant for the Angular frontend
- Create an application registration in the B2C tenant for the Web API backend
- Update the
b2c/policies/appsettings.json
with the values from steps 1-5 - Build the custom policies in Visual Studio Code.
Documentation here
Here are the instructions. Follow them for the B2C tenant.
The frontend of the app needs to be represented in b2c, i.e. b2c needs to know about it as "[relying party(https://en.wikipedia.org/wiki/Relying_party)]" application, also known as a service provider in the SAML days of yore.
Follow the steps here
- Instead of naming it webapp1, call it: Contoso Portal Frontend
This needs to represent the Angular app running in the browser. Set the clientID property in app.module.ts in the sample to the app id (client id) once this is created.
imports: [
MsalModule.forRoot({
clientID: '<here is where the application id goes>',
...
}),
The encryption and signing keys plus the application registrations are needed to get custom policies working.
Follow the instructions here, but ignore the instructions where it says to create a Facebook key.
You don't need to get the custom policy start pack, but you can look over it if you want to.
Upload the policy files in b2c/policies
to B2C.
- Select the Identity Experience Framework menu item in your B2C tenant in the Azure portal.
- Select Upload custom policy.
Upload the base file first, followed by the extension files, then the "profile" files. Example:
- TrustFrameworkBase.xml
- TrustFrameworkExtensions.xml
- SignUpOrSignin.xml
- ProfileEdit.xml
- PasswordReset.xml
https://devblogs.microsoft.com/aspnet/jwt-validation-and-authorization-in-asp-net-core/ https://developer.okta.com/blog/2018/03/23/token-authentication-aspnetcore-complete-guide