我将 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/