ASP.NET Core的Microsoft身份验证方案是什么?

5

我正在使用 Microsoft 的身份验证设置 没有 ASP.NET Core Identity 的社交登录提供程序。链接的教程以谷歌为例,并提供了获取其身份验证方案的代码 DefaultChallengeScheme

Microsoft 的身份验证方案是什么?我一直找不到它。

我的 Startup.cs > ConfigureServices 方法:

public void ConfigureServices(IServiceCollection services)
{
    //set up using this tutorial https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/social-without-identity?view=aspnetcore-2.2
    services
        .AddAuthentication(authenticationOptions =>
        {
            authenticationOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            authenticationOptions.DefaultChallengeScheme = //??? what goes here
        })
        .AddCookie()
        .AddMicrosoftAccount(microsoftOptions =>
        {
            microsoftOptions.ClientId = Configuration["Authentication:Microsoft:ClientId"];
            microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
        });

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

最有可能的情况是:authenticationOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; 请参见 https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x?view=aspnetcore-3.1 - Robert Harvey
1个回答

1

用于身份验证方案的字面值是Microsoft。 您可以使用常量MicrosoftAccountDefaults.AuthenticationScheme访问此值:

authenticationOptions.DefaultChallengeScheme = 
    MicrosoftAccountDefaults.AuthenticationScheme;

这里是常量的源代码

public static class MicrosoftAccountDefaults
{
    public const string AuthenticationScheme = "Microsoft";

    // ...
}

它在底层使用基于cookie的身份验证吗?我的意思是,一旦用户得到验证,MVC应用程序如何持久化状态?虽然我查看了代码,但没有找到任何实现Microsoft身份验证方案的Context.SignInAsync()。 - Ankush Jain

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