django - Nginx password authentication keeps prompting for password -
i want upload development branch of website can show clients , make tests in environment close production possible (with code may not ready production). password protect site.
i'm developing website using django , use nginx serving website (with uwsgi). manage prompted password applying following directives:
auth_basic "restricted content"; # tried "private property" auth_basic_user_file /etc/nginx/.htpasswd; but problem after entering first password properly, keeps prompting me user & password again; if every api call need authenticated.
i think issue might configuration file, here's site.conf file:
server { listen 80; server_name panel.mysite.dev; root /path/to/my/app/front/dist; ### i've tried 'auth_basic' here location / { root /path/to/my/app/front/dist; index index.html; auth_basic "private property"; auth_basic_user_file /etc/nginx/.htpasswd; } location /media { rewrite ^(.*)$ http://media.mysite.dev$1; } location /static { rewrite ^(.*)$ http://static.mysite.dev$1; } } server { listen 80; server_name api.mysite.dev; ### i've tried 'auth_basic' here location /api { client_max_body_size 25m; uwsgi_pass unix:/tmp/api.mysite.dev.sock; include /path/to/my/app/back/uwsgi_params; } } server { listen 80; server_name media.mysite.dev; root /path/to/my/app/media; add_header 'access-control-allow-origin' '.*\.mysite\.[com|dev]'; location / { root /path/to/my/app/media; } } server { listen 80; server_name static.mysite.dev; root /path/to/my/app/static; if ($http_origin ~* (https?://.*\.mysite\.[com|dev](:[0-9]+)?)) { set $cors "true"; } location / { if ($cors = "true") { add_header 'access-control-allow-origin' "$http_origin"; } } } my question: there way remember password once entered , allow authenticated users navigate easily? or missing trivial?
edit: in django settings.py:
authentication_backends = ( 'oauth2_provider.backends.oauth2backend', 'django.contrib.auth.backends.modelbackend', 'allauth.account.auth_backends.authenticationbackend', ) ... rest_framework = { ... default_authentication_classes': ( 'rest_framework.authentication.tokenauthentication', 'oauth2_provider.ext.rest_framework.oauth2authentication', ), thank in advance. appreciated
basic authentication uses authorization header transmit user , password. django rest also uses header in tokenauthentication authentication backend. nginx does not support multiple authorization headers, if try login , use token authentication simultaneously, things break.
a solution requiring no changes django app use means of authentication in nginx, e.g., client certificates, or, can use ngx_http_auth_request_module check whether signed session cookie set/valid or if request ip in (temporary) whitelist, , redirect user page login form otherwise.
Comments
Post a Comment