gpt4 book ai didi

Django OAuth2错误: invalid_client and client_id=None when client_id has been provided

转载 作者:行者123 更新时间:2023-12-02 05:40:47 25 4
gpt4 key购买 nike

我正在使用 django-social-auth 为我的 django 项目进行 google apps 身份验证。我从我的域的 Google api 控制台获取了客户端 ID 和 key 。并按如下方式插入我的应用程序中的值:

    **settings.py**

MIDDLEWARE_CLASSES = (
'social_auth.middleware.SocialAuthExceptionMiddleware',
)

LOGIN_URL = '/login/google-oauth2/'
LOGIN_REDIRECT_URL = '/profile'
LOGIN_ERROR_URL = '/login-error/'

AUTHENTICATION_BACKENDS = (
'social_auth.backends.google.GoogleOAuth2Backend',
'django.contrib.auth.backends.ModelBackend',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"social_auth.context_processors.social_auth_by_type_backends",
)

SOCIAL_AUTH_ENABLED_BACKENDS = ('google',)
SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'

GOOGLE_OAUTH2_CLIENT_ID = '***.apps.googleusercontent.com'
GOOGLE_OAUTH2_CLIENT_SECRET = '****'
GOOGLE_WHITE_LISTED_DOMAINS = ['127.0.0.1:8000']

SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
SOCIAL_AUTH_RAISE_EXCEPTIONS = False
SOCIAL_AUTH_PROCESS_EXCEPTIONS = 'social_auth.utils.log_exceptions_to_messages'

INSTALLED_APPS = (
'social_auth', )

...

    **urls.py**

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView
from django.contrib.auth.views import logout
admin.autodiscover()

urlpatterns = patterns('',

url(r'^admin/', include(admin.site.urls)),
url(r'', include('social_auth.urls')),
url(r'^$', TemplateView.as_view(template_name="login.html")),
url(r'^logout/$', logout, {'next_page': '/'}, name='gauth_logout'),
url(r'^profile/$', TemplateView.as_view(template_name="profile.html")),
)

...

     **login.html**

<p>Use your work email credentials to sign in to this application:
<a href="{% url 'socialauth_begin' 'google-oauth2' %}">Sign In</a>
</p>

问题是,当我单击登录时,我被重定向到错误:Invalid_client 页面,其中包含详细信息:

      Request Details
cookie_policy_enforce=false
scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
response_type=code
redirect_uri=http://127.0.0.1:8000/complete/google-oauth2/
state=WZWyJgDRfeW4RneRynqSZ3nSy0Bzs0v6
client_id=None

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile&state=WZWyJgDRfeW4RneRynqSZ3nSy0Bzs0v6&redirect_uri=http://127.0.0.1:8000/complete/google-oauth2/&response_type=code&client_id=None

尽管我在项目中提供了正确的 client_id,但页面(从 url 可以看出)显示尚未提供。如果我手动将其插入网址,我会被重定向到权限页面。

此外,当我接受权限时,我收到 AuthCanceled at/complete/google-oauth2/ 错误。是不是我的项目没有正确读取social_auth设置?

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

我也遇到了同样的问题,只是改变

GOOGLE_OAUTH2_CLIENT_ID = '***.apps.googleusercontent.com'
GOOGLE_OAUTH2_CLIENT_SECRET = '****'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '****.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='****'

在settings.py文件中

关于Django OAuth2错误: invalid_client and client_id=None when client_id has been provided,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19097638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com