2015-11-11 27 views
1

我用django restframework & django-oauth-toolkit
我測試的localhost我的代碼工作,API效果很好Django的OAuth的工具包不與Apache

這是響應頭:

Allow → GET, POST, HEAD, OPTIONS 
Content-Type → application/json 
Date → Wed, 11 Nov 2015 09:41:50 GMT 
Server → WSGIServer/0.1 Python/2.7.10 
Vary → Accept, Authorization, Cookie 
X-Frame-Options → SAMEORIGIN 

但我把這個計劃在虛擬機上使用apache
oauth不起作用。我用的是正確的道理,但得到401 UNAUTHORIZED

{ 
    "detail": "Authentication credentials were not provided." 
} 

這是響應頭:

Allow → GET, POST, HEAD, OPTIONS 
Connection → Keep-Alive 
Content-Length → 58 
Content-Type → application/json 
Date → Wed, 11 Nov 2015 09:40:37 GMT 
Keep-Alive → timeout=5, max=100 
Server → Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 
Vary → Accept,Authorization 
WWW-Authenticate → Bearer realm="api" 
X-Frame-Options → SAMEORIGIN 

爲什麼會出現這種情況??? 請指引我

settings.py

OAUTH2_PROVIDER = { 
    'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}, 
} 


AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend', 
    'oauth2_provider.backends.OAuth2Backend', 
) 


REST_FRAMEWORK = { 
    'DEFAULT_AUTHENTICATION_CLASSES': (
     'oauth2_provider.ext.rest_framework.OAuth2Authentication', 
    ) 
} 

回答

1

如果您使用mod_wsgi的,你可能需要的地方添加:

WSGIPassAuthorization On 

在AWS elasticbeanstalk修補Apache的配置的一個骯髒的方式是增加這個命令給你.ebextensions/your-environemnt.conf

commands: 
    00_WSGIPassAuthorization: 
    command: sed -i.bak '/WSGIScriptAlias/ aWSGIPassAuthorization On' config.py 
    cwd: /opt/elasticbeanstalk/hooks 

髒,因爲它每次重新加載服務器時都會添加一行。

相關Authorization Credentials Stripped --- django, elastic beanstalk, oauth

+0

你是對的!這個命令的意思是什麼? – user2492364

+0

AWS的命令是創建一個覆蓋apache中設置的文件。它需要時不時的檢查,以防亞馬遜linux鏡像改變了鉤子的位置 –