2015-09-29 11 views
7

Authorization:ヘッダを使用して保護されたリソースの認証がローカル開発サーバを使用すると正しく動作するのを確認しようとしています。 。Django JWT Django RESTフレームワークを使用したローカルとmod_wsgiサーバの認証動作が異なります

私は、JWTベースの認証のためにdjango-rest-frameworkdjango-rest-framework-jwt libでdjango 1.8を使用しています。 Apacheサーバは、mod_wsgiのver 2.2です。これは、すべてubuntu 12.04インスタンス(python 2.7)で動作しています。

ローカルホスト上のmanage.pyのrunserverを使って作業する場合:apache2.2のmod_wsgiを持つ

# 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":"[...]"} 

壊れた場合:

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のサイトの設定

#### 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 #### 

関連する可能性の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', 
} 

答えて

9

私は同様の問題に遭遇しました。私は、Apacheの設定ファイル

WSGIPassAuthorization On 
+2

これはそれがだった正確に何だったに指示の下に行方不明になったことを把握します。 – cerd

関連する問題