我有一个Django项目,我想在其中使用Google和Facebook登录功能。使用以下给定的设置,我能够使用Facebook登录,但是当尝试使用Google登录时,我不断得到:错误:redirect_uri_mismatch
我已经尝试过授权重定向URI中的URL
http://localhost:8000/complete/google-oauth2/
http://localhost:8000/oauth/complete/google-oauth2/
Settings.py
INSTALLED_APPS= [
...
'social_django', # <-- social-auth-app-django
....
]
MIDDLEWARE = [
....
'social_django.middleware.SocialAuthExceptionMiddleware',
....
]
TEMPLATES = [
.....
'OPTIONS':{
....
'social_django.context_processors.backends', # <-- related to social auth
'social_django.context_processors.login_redirect', # <-- related to social auth
}
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
LOGIN_REDIRECT_URL = 'core:landing_page'
LOGOUT_REDIRECT_URL = 'core:landing_page'
MEDIA_ROOT = os.path.join(BASE_DIR,'pictures')
MEDIA_URL = '/pictures/'
ACCOUNT_DEFAULT_HTTP_PROTOCOL='https'
SOCIAL_AUTH_URL_NAMESPACE = 'social'
#facebook social auth details
SOCIAL_AUTH_FACEBOOK_KEY = 'XXXXXXXXXXXXXX' # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = 'XXXXXXXXXXXXXXXXXXXXX' # App Secret
#google social auth details
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'XXXXXXX-XXXXX.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'XXXXXXXXXXXXXX'
在urls.py
path('oauth/', include('social_django.urls', namespace='social')), # <-- social auth url
in html
<a class="btn button_google" href="{% url 'social:begin' 'google-oauth2' %}">LOGIN</a>
根据您的URL,http://localhost:8000/oauth/complete/google-oauth2/
是正确的。
确保没有拼写错误,等等。>