在检查Django项目中创建的应用程序时,请获得OAuth 2无效的客户端错误



我已经在django rest框架中创建了一个项目,并安装了django auth提供商,并创建了一个应用程序并生成了客户端ID和客户端秘密,以及我使用curl请求

curl -x post -d" grant_type = password& username =& password =" -u":" http://localhost:8000/o/o/token/

>

我通过给出我的用户名,密码,client_id和client_request进行测试,显示错误

{" error":" invalid_client"}

settings.py

 OAUTH2_PROVIDER = {
    # this is the list of available scopes
    'SCOPES': {'read': 'Read scope', 
               'write': 'Write scope', 
               'groups': 'Access to your groups'}
}
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        'oauth2_provider.ext.rest_framework.OAuth2Authentication',
    )
}

您正在使用'o'i n url url,因此您的 urs.py 必须包含

url(r'^o/(?P<token>[w-]+)/$', YourView.as_view()),

看来您的URL不知道URLS.PY

例如

url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view()),)

会做

curl http://127.0.0.1:8000/users/1/

正常渲染。

最新更新