【发布时间】:2020-06-26 16:17:43
【问题描述】:
我尝试将 outh2 添加到我的 django 应用程序中,所以我使用了 django oauth 工具包。 所以我按照教程进行操作,但是如果我尝试获取用户令牌,它总是会向我发送 unsupported_grant_type 错误。我该如何解决这个错误?
settings.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
)
}
OAUTH2_PROVIDER = {
# parses OAuth2 data from application/json requests
'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore',
}
urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('myapp.api.urls')),
path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]
客户类型:机密
授权类型:基于资源所有者密码
网址:http://client_id:client_secret@localhost:8000/o/token/
requirements.txt
asgiref==3.2.5
autopep8==1.5
certifi==2019.11.28
chardet==3.0.4
Django==3.0.4
django-oauth-toolkit==1.3.0
djangorestframework==3.11.0
idna==2.9
oauthlib==3.1.0
pycodestyle==2.5.0
pytz==2019.3
requests==2.23.0
sqlparse==0.3.1
urllib3==1.25.8
【问题讨论】: