djangodjango-rest-frameworkamazon-elastic-beanstalkhttp-token-authentication

Django REST framework: Token Authentication doesn't work on production


I'm creating API using Django REST framework and trying to connect my mobile app to web API. I didn't have any problems with local environment. However, after I deployed API into elastic beanstalk and tried with production url, I can never successful. API always returns 401.
I was successful in registering the user's account and token is correct and also endpoints that doesn't require authentication works as expected but I cannot authenticate the user on production environment.
Error log just say 401. What is the cause of error possibly? Anyone who has encountered the similar issue? I have no idea how I can find the cause of this kind of error.


Solution

  • 401 usually your authorization header is not reaching the application. It's a common problem in beanstalk you can fix this by adding this command to container_commands in config and then executing it.

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

    Hope this helps