“错误”:“invalid_client”django-oauth-toolkit

Aad*_*ikh 1 django django-rest-framework django-oauth

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

~/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"}
Run Code Online (Sandbox Code Playgroud)

但是当我从实时服务器上托管的同一个项目中请求访问令牌时,它给我的错误是 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"
}
Run Code Online (Sandbox Code Playgroud)

我无法理解问题出在哪里。我搜索了很多,没有找到正确的答案。请告诉我该怎么做才能摆脱这个错误。

Aad*_*ikh 5

我找到了解决方案,而不是grant_type=password我使用了grant_type=client_credentials然后我得到了访问令牌。您可以在下面看到 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"}
Run Code Online (Sandbox Code Playgroud)

或者

如果你想这样做,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"}
Run Code Online (Sandbox Code Playgroud)

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