AzureADDefaults 已过时

AzureADDefaults is obsolete

我有以下用于 Azure AD 身份验证的代码:

services
    .AddAuthorization(options =>
    {
        options.AddPolicy(name, builder =>
        {
            builder
                .AddAuthenticationSchemes(AzureADDefaults.AuthenticationScheme)
                .RequireAuthenticatedUser();
        });
    })
    .AddAuthentication(AzureADDefaults.AuthenticationScheme)
    .AddAzureAD(options =>
    {
        configuration.Bind("AzureAd", options);
    });

services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
{
    ...
}

AzureADDefaults.AuthenticationScheme 和 AzureADDefaults.OpenIdScheme 现在已过时,并显示消息“改为使用 Microsoft.Identity.Web。请参阅 https://aka.ms/ms-identity-web."。但是我找不到任何明确的文档来升级以下内容使用 Identity.Web 而不是那些过时常量的代码。

有人知道如何删除这个过时的代码吗?

这个 blog 向您展示了 Identity PlatformIdentity.Web 之间的区别。

对于Identity.Web,我们使用Microsoft.Identity.WebMicrosoft.Identity.Web.UI。尝试查看此 sample,它使用 AddMicrosoftIdentityWebAppAuthentication 登录用户。

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        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.Unspecified;
            // Handling SameSite cookie according to https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
            options.HandleSameSiteCookieCompatibility();
        });

        // Sign-in users with the Microsoft identity platform
        services.AddMicrosoftIdentityWebAppAuthentication(Configuration);

        services.AddControllersWithViews(options =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            options.Filters.Add(new AuthorizeFilter(policy));
        }).AddMicrosoftIdentityUI();

        services.AddRazorPages();
    }