c# - ASP.NET Core 的 Microsoft 身份验证方案是什么?
问题描述
我正在使用 Microsoft 身份验证设置没有 ASP.NET Core 身份的社交登录提供程序身份验证。链接的教程以 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);
}
解决方案
用于身份验证方案的文字值为Microsoft
. 您可以使用常量访问此值MicrosoftAccountDefaults.AuthenticationScheme
:
authenticationOptions.DefaultChallengeScheme =
MicrosoftAccountDefaults.AuthenticationScheme;
这是常量的来源:
public static class MicrosoftAccountDefaults { public const string AuthenticationScheme = "Microsoft"; // ... }
推荐阅读
- google-api - 试驾 Speech-to-Text 异步操作 - 无结果
- asp.net-core - 启动完成后在哪里运行代码
- c# - Android - 广播中的共享首选项
- python - 代码在 Python 2 中有效,但在 Python3 中无效 TypeError: a bytes-like object is required, not 'str'
- angular - 带有打字稿的Angular版本6 Raygun设置问题
- mysql - 使用别名时的重复字段
- xml - 如何在 XPath 中获取所选元素的文本?
- xamarin.forms - 登录成功时的 Xamarin 表单导航
- xml - Ada 等价于 Python 的 dir() 方法
- mysql - MySQL 从具有不同条件的一张表中选择字段