【问题标题】:django-oauth-toolkit 'invalid client' error after deploy on AWS Elasticbeanstalk在 AWS Elasticbeanstalk 上部署后 django-oauth-toolkit 'invalid client' 错误
【发布时间】:2018-07-30 04:29:25
【问题描述】:

我在 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 应用程序请求访问令牌。

【问题讨论】:

  • 我不确定它是否相关,但您的ALLOWED_HOSTS 中有my-eb-prefix.us-west-1.elasticbeanstalk.com 吗?
  • 是的,它在我的 ALLOWED_HOSTS 中

标签: django amazon-web-services amazon-ec2 django-rest-framework django-oauth


【解决方案1】:

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

我必须在.ebextensions 文件夹中的python.config 中再添加一个命令:

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

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

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。 这对我有用:

    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"}
    

    【讨论】:

      猜你喜欢
      • 2017-08-02
      • 2014-03-02
      • 2014-09-03
      • 2020-12-11
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2017-11-01
      相关资源
      最近更新 更多