Github oauth apache2 django daphne python-social-auth |身份验证失败... redirect_uri

时间:2020-07-18 19:21:39

标签: django apache proxy

在开发过程中使用localhost:8000进行测试没有问题时,我无法在生产服务器上运行oauth。

这是设置: Apache作为反向代理-> Daphne-> Django

这是单击oauth按钮登录时的答案例外:

AuthFailed at /oauth/complete/github/

Authentication failed: The redirect_uri MUST match the registered callback URL for this application.

Request Method:     GET
Request URL:    http://nomoney.shop/oauth/complete/github/?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=bHGqHRlbQjIYNKJWrb8t46ia1XV5OuxM
Django Version:     3.0.5
Exception Type:     AuthFailed
Exception Value:    

Authentication failed: The redirect_uri MUST match the registered callback URL for this application.

Apache代理设置:

<VirtualHost *:443>
    ...
    ProxyPass / http://127.0.0.1:8002/
    ProxyPassReverse / https://127.0.0.1:8002/
    ProxyPreserveHost On
    ProxyRequests Off
    ...
</VirtualHost>

我认为,代理服务器设置会导致该错误,但是经过数小时的搜索,我找不到解决方法。

1 个答案:

答案 0 :(得分:0)

幸运的是,我在创建此问题后不久就找到了解决方案(当使用Gunicorn代替Daphne时,这是同样的问题:


我将此添加到了apache虚拟主机

RequestHeader set X-Forwarded-Proto 'https' env=HTTPS

并将其添加到django settings.py

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

更多信息: https://ubuntu.com/blog/django-behind-a-proxy-fixing-absolute-urls

相关问题