Search code examples
c#azureazure-active-directoryazure-ad-b2cmicrosoft-identity-web

AzureADB2CDefaults obsolete, how do I replace it?


I'm in the process of updating some nuget packages and noticed that AzureADB2CDefaults has been made obsolete. I know that Microsoft.Identity.UI has incorporated AzureADB2C into it but I'm unsure how to use it whilst still referencing AzureADB2C, the code below is whats causing this warning:

 services.AddAuthentication(
            options =>
            {
                options.DefaultScheme = AzureADB2CDefaults.AuthenticationScheme;
            })

I've tried setting DefaultScheme to just a string of "AzureADB2" I've also tried adding:

.AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAdB2C"), 
                        Constants.AzureAdB2C, null);

but not having much luck.

Is there any way to reference azure active directory with microsoft identity? Any suggestions on how to replace this bit of code would be much appreciated


Solution

  • Note that: Microsoft.AspNetCore.Authentication.AzureADB2C.UI Nuget package is obsolete and Microsoft advises to use the Microsoft.Identity.Web package.

    To resolve the issue, install the Latest version of Microsoft.Identity.Web and Microsoft.Identity.Web.UI.

    In the startup.cs file replace the below code:

     services.AddAuthentication(
                options =>
                {
                    options.DefaultScheme = AzureADB2CDefaults.AuthenticationScheme;
                })
    

    with

    services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)  
    .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureADB2C"));
    

    and instead of using services.AddRazorPages(); replace it with services.AddRazorPages().AddMicrosoftIdentityUI();

    And also make changes in code by referring to this blog by Andreas Helland.

    After making the changes, the code will execute successfully:

    enter image description here

    enter image description here

    For more in detail, refer below links:

    Migrating Azure AD B2C integration going from .NET Core 3.1 to .NET 5 by Andreas Helland

    Azureb2c login is not connecting to account controller by killswitch