2013-07-15 20 views
6

Non riesco a disconnettere il mio utente corrente dalla modalità browser della rest api.Disconnessione non funzionante

Questo è il mio impostazioni

REST_FRAMEWORK = { 
       'PAGINATE_BY': 10, 
       'DEFAULT_AUTHENTICATION_CLASSES': ( 
         'rest_framework.authentication.BasicAuthentication', 
         'rest_framework.authentication.SessionAuthentication', 
         'rest_framework.authentication.TokenAuthentication', 
               ), 
        'DEFAULT_PERMISSION_CLASSES': ( 
         'rest_framework.permissions.IsAuthenticated', 
            ), 
       } 

Forse perché ho usato le sessioni? Aiuto di Pls.

la richiesta e la risposta intestazioni:

Request URL:`http://localhost:8000/api/api-auth/logout/?next=/api/city/` 
Request Method:GET 
Status Code:302 FOUND 
Request Headers: 
--------------- 
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:en-US,en;q=0.8 
Connection:keep-alive 
Cookie:sessionid=j7qebcdjdwzwqlmep4eyq3svuial43uv; csrftoken=vK3Ghn3QFVbCe3nKx1LDZBTzM7sRiDym 
Host:127.0.0.1:8000 
Referer:`http://localhost:8000/api/city/` 
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36 
Query String Parametersview sourceview URL encoded 
next:/api/city/ 
Response Headers 
---------------- 
Content-Type:text/html; charset=utf-8 
Date:Mon, 15 Jul 2013 20:46:35 GMT 
Location:`http://localhost:8000/api/city/` 
Server:WSGIServer/0.1 Python/2.7.4 
Set-Cookie:sessionid=b1x24z93dqu384lqirtv5r9npy16s0qx; expires=Mon, 29-Jul-2013 20:46:35 GMT; httponly; Max-Age=1209600; Path=/ 
Vary:Cookie 

risposta

12

risolto! Era a causa dell'abilitazione di BasicAuthentication. Immagino di aver effettuato l'accesso tramite l'accesso HTTP nel browser e che il logout non abbia funzionato correttamente. Ho rimosso BasicAuthentication e tutto sembra funzionare correttamente ora.

+0

Commentando BasicAuthentication ha funzionato bene fino a quando stavo usando farmaci generici, quando sono passato di nuovo a APIView io sono ancora in grado per disconnettersi – Punit

2

In realtà il logout sta lavorando, ma durante il reindirizzamento (ad una visione che richiede l'autenticazione, perché usiamo il permesso IsAuthenticated) alla fine di logout, BasicAuth auth la richiesta di nuovo usando cache HTTP informazioni di intestazione di autenticazione:

auth = request.META.get('HTTP_AUTHORIZATION', b'') 

Così come detto OP, possiamo disabilitare BasicAuth e usare solo SessionAuth. Ma il fatto è che a volte potremmo aver bisogno di accedere alle API senza GUI, possiamo invece usare TokenAuth. Poiché BasicAuth/TokenAuth non è comunque così sicuro (https://tools.ietf.org/html/rfc2617), potrebbe essere meglio utilizzare OAuth2 o altri schemi di autenticazione più sicuri. Dipende comunque dalle richieste.

1

ho incontrato questo problema oggi e risolto modificando l'ordine a quanto segue:

'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.SessionAuthentication', 
    'rest_framework.authentication.BasicAuthentication', 
    'rest_framework.authentication.TokenAuthentication', 
),