Navigating the Latest B2C Library Updates with Azure AD


Navigating the Latest B2C Library Updates with Azure AD

Upgrade to the AzureADB2C.UI library if you haven't done so already!


  • A configuration class containing all possible settings you think you'll need to get B2C going - oftentimes too many
  • A class similar to OpenIdConnectOptionsSetup in the sample
  • A Session class to return your Challenge methods against the directory

This code hasn't really changed in some time. But if you just updated your libraries, you'll find that your dependencies did. I just updated these libraries in a project I've been working on since last fall and somehow managed to break everything. While my dependencies didn't seem to change, the dependencies of my dependencies did, creating breaking changes with exceptions pointing to this MSAL wiki page which seems to indicate that more breaking changes were ahead.

To be fair, this is a long time coming. I've been using this same code over a number of different projects over the past couple of years, making adjustments here and there as needed over the past couple of years, but all in all running with the same collection of code.

So what's the fix? Remove these packages and reference Microsoft.AspNetCore.Authentication.AzureADB2C.UI instead.

This handy little library very conveniently hides away lots of details, giving you a configuration object, an Account object for login/logout/profile tasks, and other conveniences to the point where all you do is add two lines of code:

    services.Configure<CookiePolicyOptions>(options =>
        // This lambda determines whether user consent 
        //for non-essential cookies is needed for a given request.
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;

        .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));

Two Caveats

The scaffolding code in the JetBrains Rider project worked perfectly for some sample apps I tried out over the past couple of months (which is how I discovered this handy library). HOWEVER, today's library updates creates some breaking changes.

When migrating into the B2C UI library, I ran into this error when trying to authenticate:

HttpRequestException: Response status code does not indicate success: 404 (Not Found).


IOException: IDX20804: Unable to retrieve document from: '[PII is hidden]'.
    .GetDocumentAsync(string address, CancellationToken cancel)

InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'.
.GetConfigurationAsync(CancellationToken cancel)

If you're using the URL in the Instance property of this configuration file:

  "AzureAdB2C": {
    "Instance": "",
    "ClientId": "11111111-1111-1111-11111111111111111",
    "CallbackPath": "/signin-oidc",
    "Domain": "",
    "SignUpSignInPolicyId": "",
    "ResetPasswordPolicyId": "",
    "EditProfilePolicyId": ""

Congratulations! Your authentication process is broken! Please go to all of your 3rd parties and replace it with because that's what's being used now.

However - if you're using the domain provided some time back, you're in good shape - it still works. If you're not using, now is a good time to update everything to use it instead of

Your appsettings.{Environment}.json should look something like this:

  "AzureAdB2C": {
    "Instance": "",
    "ClientId": "11111111-1111-1111-11111111111111111",
    "CallbackPath": "/signin-oidc",
    "Domain": "",
    "SignUpSignInPolicyId": "B2C_1_SUSI",
    "ResetPasswordPolicyId": "B2C_1_RP",
    "EditProfilePolicyId": "B2C_1_PE"

Looking for help building or integrating your web application with Azure AD B2C? Contact us for a quote - not only is it free, but we can help you find what you're looking for at a better price than most consulting firms!