django - "error": "invalid_client" django-oauth-toolkit

标签 django django-rest-framework django-oauth

我正在使用带有 django-oauth-toolkit 的 django rest 框架。当我在本地主机上请求访问 token 时,它会给我访问 token ,如下所示

~/django_app$ curl -X POST -d "grant_type=password&username=<Your-username>&password=<your-password>" -u"<client-id>:<client-secret>" http://localhost:8000/o/token/
{"access_token": "8u92BMmeZxvto244CE0eNHdLYWhWSa", "expires_in": 36000, "refresh_token": "faW06KKK71ZN74bx32KchMXGn8yjpV", "scope": "read write", "token_type": "Bearer"}

但是当我从托管在实时服务器上的同一个项目请求访问 token 时,它给我错误信息作为 invalid_client。

~/django_app$ curl -X POST -d "grant_type=password&username=<Your-username>&password=<your-password>" -u"<client-id>:<client-secret>" http://<your-domain>/o/token/ 
{
    "error": "invalid_client"
}

我不明白问题出在哪里。我搜索了很多,但没有找到正确的答案。请告诉我如何消除此错误。

最佳答案

我找到了解决方案,而不是 grant_type=password 我使用了 grant_type=client_credentials 然后我得到了访问 token 。您可以在下面看到 curl 命令。

curl -X POST -d "grant_type=client_credentials&client_id=<your-client id>client_secret=<your-client secret>" http://your-domain/o/token/
{"scope": "read write", "token_type": "Bearer", "expires_in": 36000, "access_token": "ITx5KCjupsdbvbKvNQFyqZDEw6svSHSfdgjh"}

如果你想用 grant-type=password 来完成,那么这里是命令:

curl -X POST -d "grant_type=password&username=<your-username>&password=<your-password>&client_id=<your-client id>&client_secret=<your-client secret>" http://your-domain/o/token/
{"access_token": "0BVfgujhdglxC7OHFh0we7gprlfr1Xk", "scope": "read write", "token_type": "Bearer", "expires_in": 36000, "refresh_token": "AwffMPzNXvghlkjhs8dpXk7gbhhjhljlldfE2nI"}

我提到了这个https://developer.amazon.com/de/docs/adm/request-access-token.html因为我的应用程序是在 AWS 上。

关于django - "error": "invalid_client" django-oauth-toolkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54003651/

相关文章:

django-rest-framework - 我是否需要在 Django Rest Framework 的 ViewSet 和 Serializer 中声明查询集?

python - 使用 Django OAuth2 工具包生成单一访问 token

Django - 通过上传小部件保存 Cloudinary 对象

python - 使用装置或脚本预填充数据库?

python - 如何在 Django Orm 中获取每个组的最新 n 条记录

python - DRF导入错误: cannot import name 'action' on v3. 8.2

python - 如何在 DRF 中访问 ListSerializer 父类的 serializer.data?

django - 使用 session 保存和检索表单?

python - Django:将数据添加到 JWT 有效负载

django-rest-framework - “type”对象不可使用 Django Rest Framework 和 django oauth2-toolkit 进行迭代