3

我在 django/django-rest-framework 应用程序中使用 django-oauth-toolkit。当我在本地主机上以开发模式请求访问令牌时,它可以正常工作:

dev@devComp:$ curl -X POST -d "grant_type=password&username=
<user_name>&password=<password>" -u"<client_id>:<client_secret>" 
http://localhost:8000/o/token/
{"access_token": "fFySxhVjOroIJkD0IuEXr5WIhwdXg6", "expires_in": 
36000, "token_type": "Bearer", "scope": "read write groups", 
"refresh_token": "14vhyaCZbdLtu7sq8gTcFpm3ro9YxH"}

但是,如果我从部署在 AWS Elasticbeanstalk 上的完全相同的应用程序请求访问令牌,我会收到“无效客户端”错误:

dev@devComp:$ curl -X POST -d "grant_type=password&username=
<user_name>&password=<password>" -u"<client_id>:<client_secret>" 
http://my-eb-prefix.us-west-1.elasticbeanstalk.com/o/token/
{"error": "invalid_client"}

请告诉我该怎么做才能摆脱此错误,并通常从部署在 AWS 的 django 应用程序请求访问令牌。

4

2 回答 2

2

经过一番研究,我现在可以自己给出答案:

我不得不在我python.config的 in.ebextensions文件夹中再添加一个命令:

...
container_commands:
  ...    
  03wsgipass:
    command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'

之后,AWS 允许传入的请求通过授权,并且我得到了没有错误的响应。

于 2018-02-22T15:02:56.307 回答
0

I was also facing the same problem. This worked for me:

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"}
于 2019-01-02T12:41:20.023 回答