在 AWS Elasticbeanstalk 上部署后出现 django-oauth-toolkit 'invalid client' 错误

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

我将 django-oauth-toolkit 与我的 django/django-rest-framework 应用程序一起使用。当我在本地主机上以开发模式请求访问 token 时,它工作正常:

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 上的完全相同的应用程序请求访问 token ,我会收到“无效客户端”错误:

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 应用程序请求访问 token 。

最佳答案

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

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

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

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

关于在 AWS Elasticbeanstalk 上部署后出现 django-oauth-toolkit 'invalid client' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48874619/

相关文章:

amazon-web-services - 适用于 EC2 的 AWS CloudFormation 蓝/绿部署

java - 启用 amazon dynamodb TTL(生存时间)的 api 方式是什么?

hosting - 适用于 Windows .NET 应用程序的云机

python - 失去与 MySQL 服务器的连接

django - celery 4.0.0 和基于类的任务工作流程

node.js - NodeJS 流出 AWS Lambda 函数

amazon-web-services - AWS Bitnami 在 Ec2 上启用 https

ubuntu - 在 Amazon EC2 ubuntu 上获取 Microsoft Calibri 字体

java - 在django框架中使用java代码

python - Django 中的动态字段计算