Facebook Oauth可以使用,但是Google Oauth2错误:Django中的redirect_uri_mismatch

问题描述 投票:0回答:1

我有一个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

in html

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

in google + apienter image description here

python django google-oauth facebook-oauth
1个回答
1
投票

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

确保没有拼写错误,等等。>

© www.soinside.com 2019 - 2024. All rights reserved.