Django Rest Framework derrière l’authentification de base HTTP

Si mon service Web (alimenté par Django Rest Framework, v2.3.8) se trouve dans un emplacement protégé par l’authentification de base HTTP de Nginx, comme ceci:

location / { auth_basic "Ressortingcted access"; auth_basic_user_file /path/to/htpasswd; uwsgi_pass django; include /etc/uwsgi/config/uwsgi_params; } 

Ensuite, lorsqu’un utilisateur s’authentifie et tente d’accéder à l’API, la réponse suivante est obtenue pour toutes les vues:

 {"detail": "Invalid username/password"} 

Django Rest Framework récupère-t-il l’en-tête d’autorisation HTTP (destiné à Nginx) même si la vue ne nécessite aucune authentification? Si oui, comment devrais-je y aller?

Toute aide serait grandement appréciée.

Par défaut, Django Rest Framework dispose de deux classes d’authentification, voir ici .

 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.BasicAuthentication' )} 

Vous pouvez désactiver l’authentification de la structure restante si vous n’en avez pas besoin.

 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': () } 

Ou vous pouvez supprimer uniquement BasicAuthentication car cela fonctionnera dans votre cas.

 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication' )} 

Comme indiqué dans un autre article, vous devez append une virgule à côté de la classe d’authentification ou lancer une erreur TypeError.

 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', #comma added here ) 

Source: https://stackoverflow.com/a/22697034/5687330