5

I'm working with Django Rest Framework and Django Rest Framework JWT, but I'm running into an issue in regards to local behavior vs external behavior.

When I make a POST request to get a JWT token, everything works as desired both locally and on my EC2 instance. However, once I have the token, when I make a request to my server that requires authentication, only my local server returns the expected response. On my deployed server, I get the following error:

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

What I've tried so far:

Editing http.conf by sshing into my server and enabling WSGIPathAuthorization. (saw a similar post here and tried the solution)

What could be causing this behavior? My local machine and my deployed code are identical, leading me to believe that this has something to do with server-side configuration.

All help is appreciated. Thanks!

rustyshackleford
  • 692
  • 1
  • 7
  • 22

3 Answers3

5

You mentioned ElasticBeanstalk.

You can add this to your container commands which will be executed during deployment.

01_wsgipass:
 command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'
Enthusiast Martin
  • 3,041
  • 2
  • 12
  • 20
1

Simply restarting Apache after enabling WSGPPathAuthorization fixed my error. For those of you who encounter something similar, here's what I did:

  1. SSH into the server

  2. Navigate to where your http.conf file is stored (in Apache, this is usually etc/httpd/http.conf)

  3. Edit http.conf, adding WSGIPathAuthorization On.

  4. Restart Apache by running sudo service httpd restart.

rustyshackleford
  • 692
  • 1
  • 7
  • 22
0

This problem usually occurs when you do configure wsgi with apache on EC2 instance. Bascially its the problem in apache configuration, it has nothing to do with AWS EC2. As apache bydefault do not process Authorization headers, so in order to make that happen we need to configure its files. For ubuntu

cd /etc/apache2/apache2.conf

paste the following line

WSGIPassAuthorization On
Christopher Nolan
  • 930
  • 1
  • 11
  • 15