2015-09-29 20 views
7

Ich versuche zu ermitteln, warum die Authentifizierung für geschützte Ressourcen mit dem Header Authorization: bei Verwendung eines lokalen Entwicklungsserver richtig funktioniert, aber nicht auf meinem deployed apache 2.2 w/mod_wsgi Implementierung .Django JWT Authentifizierungsverhalten zwischen lokalen & mod_wsgi Servern mit Django REST-Framework

Ich verwende django 1.8 mit django-rest-framework und die django-rest-framework-jwt lib für JWT-basierte Authentifizierung. Der Apache-Server ist ver 2.2 mit mod_wsgi. Dies läuft alles auf einer Ubuntu 12.04-Instanz (Python 2.7).

Arbeits Fall mit manage.py runserver auf localhost:

# manage.py runserver is running 
curl -s -X POST \ 
    -d '{"username":"[email protected]", "password":}' \ 
    http://localhost:8000/portfolio/login 

# Response as expected: 
##> {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp..."} 

# Using above token as $TOKEN_STR with JWT prefix for Auth header: 
curl -X GET -H "Content-Type: application/json" \ 
    -H "Authorization: $TOKEN_STR" \ 
    http://localhost:8000/portfolio 

# Response as expected 
##> {"data":"[...]"} 

Gebrochene Fall mit apache2.2 mod_wsgi:

curl -s -X POST \ 
    -d '{"username":"[email protected]", "password":}' \ 
    http://myremote.com/django/portfolio/login 

# Response as expected: 
##> {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp..."} 

# Using above token as $TOKEN_STR with JWT prefix for Auth header: 
curl -X GET -H "Content-Type: application/json" \ 
    -H "Authorization: $TOKEN_STR" \ 
    http://myremote.com/django/portfolio 

# Response behaves as authentication not even there w/403 or 401: 
##> {"detail": "Authentication credentials were not provided."} 

Apache Website Config

#### DJANGO APP #### 
    LogLevel info 
    WSGIDaemonProcess dev processes=2 threads=15 
    WSGIProcessGroup dev 

    WSGIScriptAlias /django /webapps/django/config/wsgi.py 
    <Directory /webapps/django> 
     Order allow,deny 
     Allow from all 
    </Directory> 


    ### DJANGO APP #### 

Möglicherweise relevant configs

config.py

## Django rest frameowkr config 
REST_FRAMEWORK = { 
    'DEFAULT_PERMISSION_CLASSES': (
     'rest_framework.permissions.IsAuthenticated', 
    ), 
    'DEFAULT_AUTHENTICATION_CLASSES': (
     'rest_framework.authentication.SessionAuthentication', 
     'rest_framework.authentication.BasicAuthentication', 
     'rest_framework_jwt.authentication.JSONWebTokenAuthentication', 

    ) 
} 

JWT_AUTH = { 
    'JWT_ENCODE_HANDLER': 
     'rest_framework_jwt.utils.jwt_encode_handler', 
    'JWT_DECODE_HANDLER': 
     'rest_framework_jwt.utils.jwt_decode_handler', 
    'JWT_PAYLOAD_HANDLER': 
     'rest_framework_jwt.utils.jwt_payload_handler', 
    'JWT_PAYLOAD_GET_USER_ID_HANDLER': 
     'rest_framework_jwt.utils.jwt_get_user_id_from_payload_handler', 

    'JWT_RESPONSE_PAYLOAD_HANDLER': 
     'rest_framework_jwt.utils.jwt_response_payload_handler', 
    'JWT_SECRET_KEY': SECRET_KEY, 
    'JWT_ALGORITHM': 'HS256', 
    'JWT_AUTH_HEADER_PREFIX': 'JWT', 
} 

Antwort

9

Ich habe ähnliches Problem aufgetreten. Ich finde heraus, dass ich unter Direktive in der Apache-Konfigurationsdatei

+2

fehlte Das war genau was es war. – cerd