django - 出现错误 {"error": "invalid_client"} when creating access token in django

标签 django access-token django-settings clientid oauth-provider

我已经在我的项目中创建了应用程序并成功创建。我从中收到了客户端 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.

You can read more about this here

关于django - 出现错误 {"error": "invalid_client"} when creating access token in django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72448232/

相关文章:

python - Django查询集在查询中获取空值

django - 如何在 Django 中访问远程 PostgreSQL 数据库服务器(只读事务)?

azure - 更改 Azure AD B2C 访问 token 生命周期不起作用

security - 是否可以使用我的服务器作为代理来获取 jwt 刷新 token ?

django - 如何在我的开发环境中模拟我的 Django 项目的路径与生产环境相同?

python - Django - AttributeError _committed

php - "errorType": "invalid_client", "message":"授权 header 格式无效

python - 从外部源更改 Django 的设置

python - 我无法更改主 Django 项目设置文件

python - 是否可以减少样板函数上的参数数量?