AWS Lightsail Django "Authentication credentials were not provided."

Keywords: Django - AWS - Technical issue - Application configuration

bnsupport ID: 3139b656-2a46-baed-b2b0-5f4a55db6d8f

bndiagnostic output:

? Apache: Found possible issues
https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-errors-apache/

bndiagnostic failure reason: The suggested guides are not related with my issue

Description:
Hi, I deployed my django backend app on aws lightsail, however I encountered the

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

error when I was trying to do a get request. I used postman, on the header , there is Authorization with a valid token.

Here is my httpd-app.conf file:

<IfDefine !IS_DJANGOSTACK_LOADED>
  Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack   processes=2 threads=15    display-name=%{GROUP}
</IfDefine>

<Directory "/opt/bitnami/myappl/myapp">
    Options +MultiViews
    AllowOverride All
    <IfVersion >= 2.3>
Require all granted
    </IfVersion>

<IfModule mod_headers.c>
Header set Access-Control-Allow-Headers "Authorization"
    </IfModule>

WSGIProcessGroup wsgi-djangostack

WSGIApplicationGroup %{GLOBAL}
</Directory>

Alias /tutorial/static "/opt/bitnami/python/lib/python3.8/site-packages/django/contrib/admin/static/"
WSGIScriptAlias /tutorial '/opt/bitnami/projects/myapp/myapp/wsgi.py'

It seems the header was striped, I think I missed something in the config.
Thank you very much for your time.

Hi @wei1

Thanks for using Bitnami Django!

According to this post in StackOverflow:

https://stackoverflow.com/questions/26906630/django-rest-framework-authentication-credentials-were-not-provided

you may need to set WSGIPassAuthorization On in order for the Authentication Header to be considered when using mod_wsgi (which the stack uses). Let’s try to add that and see if that solves your issue:

<IfDefine !IS_DJANGOSTACK_LOADED>
  Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack   processes=2 threads=15    display-name=%{GROUP}
</IfDefine>

<Directory "/opt/bitnami/myappl/myapp">
    Options +MultiViews
    AllowOverride All
    <IfVersion >= 2.3>
Require all granted
    </IfVersion>

<IfModule mod_headers.c>
Header set Access-Control-Allow-Headers "Authorization"
    </IfModule>

WSGIProcessGroup wsgi-djangostack
+ WSGIPassAuthorization On
WSGIApplicationGroup %{GLOBAL}
</Directory>

Alias /tutorial/static "/opt/bitnami/python/lib/python3.8/site-packages/django/contrib/admin/static/"
WSGIScriptAlias /tutorial '/opt/bitnami/projects/myapp/myapp/wsgi.py'

You will also need to restart apache:

$ sudo /opt/bitnami/ctlscript.sh restart apache

Could you please give that a try and report back?

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

1 Like

Hi @jcarmona, thank you for your reply, after I searched more, i found out I have to add “WSGIPassAuthorization On”
in sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami.conf file, and it solved the problem.
Thanks again.
Have a wonderful day!
Best Regard!
Wei

Glad to see you were able to solve your issue! We are marking the previous answer as “Solution” and this topic as “Closed”.

If you have any other questions, please do not hesitate to let us know. Feel free to create a new topic referencing this one if necessary.

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

1 Like