背景:使用Kestrel和Apache Core作为反向代理。对本网站中的所有流量使用https协议。
我的问题是,如何使用Google API强制在回调uri中使用https而不是http来回复?
我调用Google API后收到错误消息。错误消息是“Error:redirect_uri_mismatch”。我已经使用https作为协议在Google API控制台上正确设置了回调。
请求详情如下:
> response_type=code
client_id=myclientidnum.apps.googleusercontent.com
redirect_uri=http://mysub.domain.com/signin-google
scope=openid profile email
state=long_long_code
如果您有任何想法,请给我留言。
当我尝试通过使用Kestrel的反向代理在Apache上运行的ASP.NET核心Web应用程序配置Google身份验证时,我也收到了redirect_uri_mismatch错误。
该错误是由于将授权重定向URI设置为https
。一旦我将其更改为http
,Google身份验证就可以正常运行。
因此,假设您的域名是example.com
,请更改您的授权重定向URI
https://example.com/signin-google
至
http://example.com/signin-google
问题是服务器没有使用反向代理转发的头,因此它正在请求不正确的协议。你需要:
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders =
ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();