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

时间:2020-07-08 14:58:06

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

我正在通过Microsoft身份验证设置social sign-in provider authentication without ASP.NET Core Identity。链接的教程以Google为例,提供了用于获取DefaultChallengeScheme的身份验证方案的代码。

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

我的Startup.cs> ConfigureServices方法:

public void ConfigureServices(IServiceCollection services)
{
    //set up using this tutorial https://docs.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);
}

1 个答案:

答案 0 :(得分:1)

用于认证方案的文字值为Microsoft。您可以使用常量MicrosoftAccountDefaults.AuthenticationScheme访问此值:

authenticationOptions.DefaultChallengeScheme = 
    MicrosoftAccountDefaults.AuthenticationScheme;

这是常数的source

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

    // ...
}