【问题标题】:AddMicrosoftIdentityWebApp vs AddAzureADBearerAddMicrosoftIdentityWebApp 与 AddAzureADBearer
【发布时间】:2020-12-18 01:47:33
【问题描述】:

快速入门文档最近发生了变化,我看不出有什么变化:

有什么区别:

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
        .AddMicrosoftIdentityWebApp(options =>
        {
            options.Instance = azureSecurity.Instance;
            options.Domain = azureSecurity.Domain;
            options.TenantId = azureSecurity.TenantId;
            options.ClientId = azureSecurity.ClientId;
        });

还有:

services.AddAuthentication(AzureADDefaults.JwtBearerAuthenticationScheme)
        .AddAzureADBearer(options =>
        {
            options.Instance = azureSecurity.Instance;
            options.Domain = azureSecurity.Domain;
            options.TenantId = azureSecurity.TenantId;
            options.ClientId = azureSecurity.ClientId;
        });

【问题讨论】:

    标签: c# .net asp.net-core .net-core


    【解决方案1】:

    Microsoft 正在将应用程序的 Azure Active Directory 身份验证从 ADAL 迁移到 MSAL

    新的 Microsoft 身份验证库 (MSAL) 不仅支持 AAD 身份验证方法,还支持 Facebook、Google 和 LinkedIn 等其他令牌提供程序。

    详情可见here

    因此,这两个代码段之间的区别只是从过时的 API 迁移到新引入的 API。由于示例仍然使用 AAD 作为其身份验证令牌提供程序,因此我想说它们之间没有太多功能差异。

    从 ADAL 迁移到 MSAL 时要提到的一件事是不要忘记将 /v2.0 附加到您的颁发者 URL。例如https://login.microsoftonline.com/common/v2.0。尝试在 Azure 应用服务中配置请求身份验证时,我花了几天时间才意识到这一点。

    (您可以看到旧的 AAD Auth 扩展方法在 .Net Core source code 中标有 obsolete 属性)

    [Obsolete("This is obsolete and will be removed in a future version. Use Microsoft.Identity.Web instead. See https://aka.ms/ms-identity-web.")]
    public static class AzureADAuthenticationBuilderExtensions
    {
        /// <summary>
        /// Adds JWT Bearer authentication to your app for Azure Active Directory Applications.
        /// </summary>
        /// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
        /// <param name="configureOptions">The <see cref="Action{AzureADOptions}"/> to configure the
        /// <see cref="AzureADOptions"/>.
        /// </param>
        /// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
        [Obsolete("This is obsolete and will be removed in a future version. Use AddMicrosoftWebApiAuthentication from Microsoft.Identity.Web instead. See https://aka.ms/ms-identity-web.")]
        public static AuthenticationBuilder AddAzureADBearer(this AuthenticationBuilder builder, Action<AzureADOptions> configureOptions) =>
            builder.AddAzureADBearer(
                AzureADDefaults.BearerAuthenticationScheme,
                AzureADDefaults.JwtBearerAuthenticationScheme,
                configureOptions);
        
        ...
    

    【讨论】:

      猜你喜欢
      • 2021-02-25
      • 2021-10-11
      • 2021-04-19
      • 2020-03-11
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      相关资源
      最近更新 更多