【问题标题】:What is the Microsoft authentication scheme for ASP.NET Core?ASP.NET Core 的 Microsoft 身份验证方案是什么?
【发布时间】:2020-10-29 00:52:50
【问题描述】:

我正在使用 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);
}

【问题讨论】:

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


【解决方案1】:

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

authenticationOptions.DefaultChallengeScheme = 
    MicrosoftAccountDefaults.AuthenticationScheme;

这是常量的source

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

    // ...
}

【讨论】:

  • 它是否在后台使用基于 cookie 的身份验证?我的意思是,一旦用户得到验证,状态如何在 MVC 应用程序中持久化?不过,我查看了代码,但没有找到此 Context.SignInAsync() for Microsoft 身份验证方案的任何实现。
猜你喜欢
  • 2017-02-09
  • 2018-02-23
  • 1970-01-01
  • 2019-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
  • 2020-07-27
相关资源
最近更新 更多