Facebook Oauth works but Google Oauth2 error : redirect_uri_mismatch in Django

Facebook Oauth works but Google Oauth2 error : redirect_uri_mismatch in Django

我有一个 Django 项目,我想在其中使用 Google 和 Facebook 进行登录。通过下面给出的设置,我可以使用 Facebook 登录,但是当尝试使用 Google 登录时,我不断收到:错误:redirect_uri_mismatch

我试过在授权重定向 URI 中跟踪 url

http://localhost:8000

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

在html

    <a class="btn button_google" href="{% url 'social:begin' 'google-oauth2' %}">LOGIN</a>

在google+api

根据您的 URL,http://localhost:8000/oauth/complete/google-oauth2/ 是正确的。

确保没有拼写错误等