Flask-Dance 在重定向时使用 localhost 而不是 domain



我有一个使用Flask-Dance进行Google Login身份验证的应用程序。当我尝试登录时,它说我正在从 127.0.0.1:9852 重定向,这是我的应用程序在服务器中运行的位置,但我有一个 apache 配置,它正在为该地址分配服务器名称 (xxx.xxx.com(

我在谷歌控制台中注册了授权URI中的域。不过,当我尝试访问登录部分时,它说"http://127.0.0.1:9852/google/authorized,请求中的重定向 URI 与 OAuth 客户端授权的 URI 不匹配。

所以我确实注册了该地址,它确实允许我登录,但是当它尝试重定向时,它说它找不到服务器"127.0.0.1"。无论如何,我可以使用我的域作为实际授权的URI吗?

这是我的蓝图:

blueprint = make_google_blueprint(
client_id="id",
client_secret="secret",
scope=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email',
'openid'],
storage=SQLAlchemyStorage(OAuth, db.session, user=current_user),
redirect_url='questions.view_all')

编辑:这是Apache2 conf文件:

<VirtualHost *:80>
ServerName xxx.xxx.com
ServerAlias xxx.xxx.com
ServerAdmin em@il.com
# Redirect http to https
RedirectMatch 301 (.*) https://xxx.xxx.com$1
</VirtualHost>
<VirtualHost _default_:443>
ServerName xxx.xxx.com
ServerAlias xxx.xxx.com
ServerAdmin em@il.com
#   Enable/Disable SSL for this virtual host.
SSLEngine On
SSLProxyEngine On
# Web root
ProxyPass /  http://127.0.0.1:9852/
ProxyPassReverse /  http://127.0.0.1:9852/
# Log configuration
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Self signed SSL Certificate file
SSLCertificateFile      /etc/apache2/ssl/certs/cert.crt
SSLCertificateKeyFile /etc/apache2/ssl/private/cert.key
</VirtualHost>

我在谷歌控制台中注册了授权URI中的域

应在 Google 控制台中为 OAUTH 客户端应用程序注册完整的重定向网址。

当我尝试登录时,它说我正在从 127.0.0.1:9852 重定向

您给定的服务器配置将您的应用程序与 gunicorn 和 Apache 一起配置为代理服务器。

在某种程度上,请求不会传递到具有足够信息供werkzeug确定正确主机名的gunicorn服务器。

我建议在VirtualHost中使用ProxyPreserveHost指令,以使传入的主机能够传递给 gunicorn。

最新更新