Django: Rest Framework authenticate header

前端 未结 5 1578
小鲜肉
小鲜肉 2020-12-23 02:36

Using Django REST API, I\'m trying to authenticate my request.

This is what I\'m trying to send:

Content-Type: application/json, Authentication: toke         


        
5条回答
  •  独厮守ぢ
    2020-12-23 02:58

    For those who are on AWS elastic beanstalk and you are kind of stuck with apache and unless you have

    WSGIPassAuthorization On

    As mentioned by @Fiver your headers get stripped

    Instead of manually fixing this and making a new image, I made a script that checks if the last line of the conf file is WSGIPassAuthorization On and if it is not we update it and restart the server

    In my Django app I have a config folder with my sh file

    configs/server/update-apache.sh

    if [[ $(tac /etc/httpd/conf/httpd.conf | egrep -m 1 .) == $(echo 'WSGIPassAuthorization On') ]];
      then
         echo "Httpd.conf has already been updated"
      else
         echo "Updating Httpd.conf.."
         echo 'WSGIPassAuthorization On' >> /etc/httpd/conf/httpd.conf
         service httpd restart
    fi
    

    Make it excecutable before I commit it to git

    chmod +x configs/server/update-apache.sh

    Then in my python.config file I add the command at the end

    .ebextensions/python.config

    ...
    ...
    container_commands:
        01_migrate:
            command: "python manage.py migrate"
            leader_only: true
        02_collectstatic:
            command: "python manage.py collectstatic --noinput"
        03_change_perm:
            command: "chown -R wsgi:root static"
        03_update_apache:
            command: "sh configs/server/update-apache.sh"
    

    Now any new machine that starts up will have a check done to see if the server is updated and does so if need be

提交回复
热议问题