2016-12-30 94 views
2

我已经创建了Django的REST框架项目和安装的Django身份验证提供者,创造了一个应用程序,生成的客户端ID和客户端密钥,当我测试的应用程序在Django项目中创建的应用程序使用卷曲请求得到的Oauth 2无效客户端错误,同时检查

卷曲-X POST -d “grant_type =密码&用户名= &密码=” -u “:” http://localhost:8000/o/token/

我测试通过给我的用户名,密码,CLIENT_ID和client_request表示像

错误

{ “错误”: “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', 
    ) 
} 

回答

0

您使用“o'i n您的网址让你urs.py必须包含

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

貌似不知道您的网址的urls.py

对于离有充足

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

将使

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

呈现正常。

+0

url.py:url(r'^ o /',include('oauth2_provider.urls',namespace ='oauth2_provider')), – Ravi

+0

您的网址不包含考虑令牌的正则表达式部分,或者它必须是'r “^ O/$' – dmitryro

+0

它必须是'^ O /(P [\ W - ] +)$'或,如果有更多的参数后令牌'2 O /(P [\ W - ] +)/$' – dmitryro