Google 没有 ASP.NET 核心身份的登录提供商

Google sign-in provider without ASP.NET Core Identity

按照 Microsoft 在 https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/social-without-identity?view=aspnetcore-6.0 使用 Google 登录提供程序的示例,我收到一条错误消息,指出没有 DefaultSignInScheme。

然而,这是在 AddAuthentication 方法中设置的,所以我没有看到我遗漏了什么。

从 Google 重定向回 Web 应用程序后,登录-google 页面出现错误。

据我所知,我在每个细节上都遵循示例。

可以这样修改代码吗?

builder.Services.AddAuthentication(options =>
{
    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(GoogleDefaults.AuthenticationScheme, options =>
{
    options.ClientId = builder.Configuration["Authentication:Google:ClientId"];
    options.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
});

这种方法也解决了问题(设置 SignInScheme)

options.ClientId = configuration["Google:ClientId"];
options.ClientSecret = configuration["Google:ClientSecret"];
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;