问题描述
从 OpenIddict 的 Zirku Sample 开始,我想添加 Google 帐户作为登录提供程序 (nuget: Microsoft.AspNetCore.Authentication.Google
)。
我的更改包括在 AddOpenIddict(...)
之后添加 google auth 提供程序:
services.AddAuthentication()
.AddGoogle("Google",options =>
{
options.CallbackPath = "/signin-google";
options.ClientId = "0000000000000-redacted.apps.googleusercontent.com";
options.ClientSecret = "redacted";
options.SignInScheme = OpenIddictServerAspNetCoreDefaults.AuthenticationScheme;
});
添加 /signin-google
作为有效的授权端点以允许调用 SignIn:
options.SetAuthorizationEndpointUris("/connect/authorize","/signin-google")
.SetlogoutEndpointUris("/connect/logout")
.SetIntrospectionEndpointUris("/connect/introspect")
.SetUserinfoEndpointUris("/connect/userinfo");
然而,当从谷歌回来时,OpenIddict 服务器总是抱怨缺少 client_id:
fail: OpenIddict.Server.OpenIddictServerdispatcher[0] The authorization request was rejected because the mandatory 'client_id' parameter was missing.
已经尝试过这些配置选项,没有任何变化:
options.AcceptAnonymousClients();
options.Configure(op => op.AcceptAnonymousClients = true);
我做错了什么?
可以在here找到完整的日志。
(是的,我将端口更改为 6001 以重用在 google 注册的现有重定向 URL)
解决方法
options.AcceptAnonymousClients()
对代码流没有影响,因为在这种情况下 client_id
是必需参数(它只影响令牌、内省和撤销端点)。
options.SignInScheme
不能设置为属于 OpenIddict 的方案。在大多数情况下,它必须对应一个 cookie 处理程序(通常是 Identity 注册的那个)。
您还需要从 OpenIddict 管理的端点中删除 /signin-google
,因为它会阻止 Google 身份验证处理程序正常工作。