我已经在我的项目中创建了应用程序并成功创建。我从中收到了客户端 ID 和客户端 key 。 但是当我输入命令来获取访问 token 时,这会给我一条错误消息
{"error": "invalid_client"}
我输入了这个命令curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://<ip_address>:<port>/o/token/
在 Windows CMD 中使用我的用户名密码。
我已将其添加到settings.py
'oauth2_provider'
在 INSTALLED_APPS 中
OAUTH2_PROVIDER = {
# this is the list of available scopes
'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS' : [ 'django_filters.rest_framework.DjangoFilterBackend' ],
'DEFAULT_AUTHENTICATION_CLASSES' : ('oauth2_provider.contrib.rest_framework.OAuth2Authentication',),
}
但仍然得到{"error": "invalid_client"}
在 CMD 中。
Unauthorized: /o/token/
[31/May/2022 18:08:17] "POST /o/token/ HTTP/1.1" 401 27
VS code 终端中出现上述错误。
我如何解决它。
最佳答案
您尝试使用 django oauth toolkit admin 生成的 client_secret 请求 token (哈希值)。您必须在保存之前复制 client_secret。此变更于2022年4月24日实现
根据变更日志:
#1093 (Breaking) Changed to implement hashed client_secret values. This is a breaking change that will migrate all your existing cleartext application.client_secret values to be hashed with Django’s default password hashing algorithm and can not be reversed. When adding or modifying an Application in the Admin console, you must copy the auto-generated or manually-entered client_secret before hitting Save.
关于django - 出现错误 {"error": "invalid_client"} when creating access token in django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72448232/