使用kestrel在反向代理服务器中的Google API中使用HTTPS请求URI

问题描述 投票:1回答:2

背景:使用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

如果您有任何想法,请给我留言。

apache api reverse-proxy kestrel-http-server
2个回答
0
投票

当我尝试通过使用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

0
投票

问题是服务器没有使用反向代理转发的头,因此它正在请求不正确的协议。你需要:

  1. 确保您的反向代理正在设置X-Forwarded标头
  2. 在身份验证之前启用UseForwardedHeaders中间件
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = 
        ForwardedHeaders.XForwardedFor | 
        ForwardedHeaders.XForwardedProto
});

app.UseAuthentication();

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-2.1&tabs=aspnetcore2x

© www.soinside.com 2019 - 2024. All rights reserved.