AddMicrosoftIdentityWebApp与AddAzureADBearer的区别

7

快速入门文档最近有所更改,但我看不出这个变化:

以下两者有何不同:

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;
        });
1个回答

7
微软正在将应用程序的Azure Active Directory身份验证从ADAL迁移到MSAL
新的Microsoft Authentication Library(MSAL)不仅支持AAD身份验证方法,还支持其他令牌提供者,如Facebook、Google和LinkedIn。

enter image description here

详情可以在这里看到。

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

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

(您可以看到旧的AAD Auth扩展方法在.Net Core源代码中被标记为过时属性)

[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);
    
    ...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接