首页 > 解决方案 > 身份验证后无法让 python-social-auth 重定向到我的自定义 url

问题描述

我想python-social-auth重定向到/?ref=twitter用户是否通过 twitter 登录,以及/?ref=google他们是否通过 google-oauth2 登录。

我使用安装了python-social-auth库的 django 版本

pip install social-auth-app-django

到目前为止,身份验证有效,但python-social-auth始终重定向到/(即“家”)。

这是我的设置:

LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
LOGIN_REDIRECT_URL = 'home'

# Used to redirect the user once the auth process ended successfully. The value of ?next=/foo is used if it was present
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_TWITTER_LOGIN_REDIRECT_URL = '/?ref=twitter'
SOCIAL_AUTH_GOOGLE_OAUTH2_LOGIN_REDIRECT_URL = '/?ref=google'

# URL where the user will be redirected in case of an error
SOCIAL_AUTH_LOGIN_ERROR_URL = '/?err=true'
SOCIAL_AUTH_TWITTER_LOGIN_ERROR_URL = '/?ref=twitter&err=true'
SOCIAL_AUTH_GOOGLE_OAUTH2_LOGIN_ERROR_URL = '/?ref=google&err=true'

# Is used as a fallback for LOGIN_ERROR_URL
SOCIAL_AUTH_LOGIN_URL = '/'
SOCIAL_AUTH_TWITTER_LOGIN_URL = '/?ref=twitter'
SOCIAL_AUTH_GOOGLE_OAUTH2_LOGIN_URL = '/?ref=google'

# Used to redirect new registered users, will be used in place of SOCIAL_AUTH_LOGIN_REDIRECT_URL if defined.
# Note that ?next=/foo is appended if present, if you want new users to go to next, you'll need to do it yourself.
SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/?user=new'
SOCIAL_AUTH_TWITTER_NEW_USER_REDIRECT_URL = '/?ref=twitter&user=new'
SOCIAL_AUTH_GOOGLE_OAUTH2_NEW_USER_REDIRECT_URL = '/?ref=google&user=new'

# Like SOCIAL_AUTH_NEW_USER_REDIRECT_URL but for new associated accounts (user is already logged in).
# Used in place of SOCIAL_AUTH_LOGIN_REDIRECT_URL
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/?assoc=true'
SOCIAL_AUTH_TWITTER_NEW_ASSOCIATION_REDIRECT_URL = '/?ref=twitter&assoc=true'
SOCIAL_AUTH_GOOGLE_OAUTH2_NEW_ASSOCIATION_REDIRECT_URL = '/?ref=google&assoc=true'

如果有人能指出我在这里做错了什么,那将非常有帮助。

我目前正在浏览他们的文档以寻找线索。

谢谢

标签: pythondjangopython-social-authdjango-socialauth

解决方案


推荐阅读