IdentityServer4 Google 签名回调不包含 "IdentityConstants.ExternalScheme" cookie

IdentityServer4 Google sign callback doesn't include "IdentityConstants.ExternalScheme" cookie

我有一个 IdentityServer4 身份提供者服务器。在大多数情况下,我使用的是他们存储库中的模板代码。我正在尝试添加 Google 登录。我在启动时配置了 GoogleSignIn 并添加了 ClientId/ClientSecret.

当我没有在 GCP 项目中配置 return URI 时,我从 Google 得到以下错误:

"The redirect URI in the request, https://localhost:44333/signin-google, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs..."

当我添加 URI 时

然后,一旦我调用 Challenge,我立即收到来自 Google 的失败回调。

[HttpGet]
public async Task<IActionResult> Callback()
{
    var result = await HttpContext.AuthenticateAsync(IdentityConstants.ExternalScheme);
    // Here, result.Succeeded is false

    // Rest of the method...
}

可能是什么问题?

如果您已进入 Callback 方法,则听起来 Google 身份验证已成功完成。但是,由于 IdentityConstants.ExternalScheme cookie 不存在,听起来您的配置可能有点错误。

一旦 Google 身份验证处理程序完成,它将使用其 SignInScheme 属性 中设置的身份验证方案或默认登录方案登录。它将来自 Google 的声明存储到本地身份验证方法中,例如 cookie。

Google 身份验证处理程序配置使用什么方案?如果您使用的是快速入门,它可能使用 IdentityServerConstants.ExternalCookieAuthenticationScheme 而不是您正在寻找的 ASP.NET 身份 IdentityConstants.ExternalScheme