授权证书剥离--- Django的,弹性的豆茎,OAuth的弹性、证书、Django、OAuth

2023-09-11 10:44:34 作者:月牙症

我在Django Django的,其余的骨架实现的REST API和使用oauth2进行身份验证。

我测试了:

 卷曲-X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" HTTP://本地主机:8000 / oauth2 / access_token /
 

 卷曲-H授权:承载<您的访问令牌>中HTTP://本地主机:8000 / API /
 

在本地主机与文档一致成功的结果。

根证书安装帮助

当推这件事到现有的AWS弹性魔豆例如,我收到:

  {细节:没有提供身份验证凭据。 }
 

解决方案

我认为这个问题是我在Django配置或其他错误类型,而不是专注于本地主机和EB之间的差异。问题是与EB的Apache的设置。

WSGIPassAuthorization被本身设置为OFF,所以它必须被接通。这可以在* .config文件来完成你的.ebextensions文件夹使用以下命令添加:

  container_commands:
  01_wsgipass:
    命令:回响WSGIPassAuthorization在>> ../wsgi.conf
 

请让我知道如果我错过了什么,或者有更好的办法,我应该看这个问题。我无法找到任何具体关于这个畅游网络世界,认为这可能会节省故障排除,然后感到愚蠢的。别人的时间

I implemented a REST api in django with django-rest-framework and used oauth2 for authentication.

I tested with:

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/

and

curl -H "Authorization: Bearer <your-access-token>" http://localhost:8000/api/

on localhost with successful results consistent with the documentation.

When pushing this up to an existing AWS elastic beanstalk instance, I received:

{ "detail" : "Authentication credentials were not provided." }

解决方案

I thought the problem was with my configuration in django or some other error type instead of focusing on the differences between localhost and EB. The issue is with EB's Apache settings.

WSGIPassAuthorization is natively set to OFF, so it must be turned ON. This can be done in your *.config file in your .ebextensions folder with the following command added:

container_commands:
  01_wsgipass:
    command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'

Please let me know if I missed something or if there is a better way I should be looking at the problem. I could not find anything specifically about this anywhere on the web and thought this might save somebody hours of troubleshooting then feeling foolish.