sah*_*chi 73 django amazon-web-services oauth-2.0 django-rest-framework amazon-elastic-beanstalk
我使用django-rest-framework在django中实现了一个REST api,并使用oauth2进行身份验证.
我测试过:
curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/oauth2/access_token/
Run Code Online (Sandbox Code Playgroud)
和
curl -H "Authorization: Bearer <your-access-token>" http://localhost:8000/api/
Run Code Online (Sandbox Code Playgroud)
在localhost上,成功的结果与文档一致.
将其推送到现有AWS弹性beanstalk实例时,我收到:
{ "detail" : "Authentication credentials were not provided." }
Run Code Online (Sandbox Code Playgroud)
Man*_*los 53
我喜欢在标准位置上进行一些额外配置的想法.在.ebextensions目录中,使用以下命令创建wsgi_custom.config文件:
files:
"/etc/httpd/conf.d/wsgihacks.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIPassAuthorization On
Run Code Online (Sandbox Code Playgroud)
发布在这里:https://forums.aws.amazon.com/message.jspa?messageID = 376244
sah*_*chi 35
我认为问题在于我在django中的配置或其他一些错误类型,而不是关注localhost和EB之间的差异.问题在于EB的Apache设置.
WSGIPassAuthorization本身设置为OFF,因此必须打开它.这可以在.ebextensions文件夹中的*.config文件中完成,并添加以下命令:
container_commands:
01_wsgipass:
command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'
Run Code Online (Sandbox Code Playgroud)
如果我错过了什么或者有更好的方法我应该关注这个问题,请告诉我.我无法在网络上的任何地方找到任何具体的内容,并认为这可能会节省一些时间的故障排除然后感到愚蠢.
Rub*_*arí 28
我现在使用略有不同的方法.只要汤姆迪金指出env变量没有改变,sahutchi的解决方案就有效.我在EB内部挖了一下,发现了wsgi.conf模板所在的位置,并在那里添加了"WSGIPassAuthorization On"选项.
commands:
WSGIPassAuthorization:
command: sed -i.bak '/WSGIScriptAlias/ a WSGIPassAuthorization On' config.py
cwd: /opt/elasticbeanstalk/hooks
Run Code Online (Sandbox Code Playgroud)
即使在更改环境变量时,这也始终有效.希望对你有帮助.
编辑:似乎很多人仍然在回应这个问题.我有一段时间没有使用ElasticBeanstalk,但我会考虑使用下面的Manel Clos解决方案.我没有亲自试过,但似乎是一个更清洁的解决方案.这个实际上是对EBs脚本的破解,如果EB更新它们,将来可能会破坏,特别是如果它们将它们移动到不同的位置.
| 归档时间: |
|
| 查看次数: |
7432 次 |
| 最近记录: |