Merge pull request #811 from Frzk/bearer-support

Added support for 'Authorization: Bearer <TOKEN>' header...
This commit is contained in:
Eli Uriegas 2017-06-23 10:32:21 -07:00 committed by GitHub
commit dbcbf12456
2 changed files with 18 additions and 4 deletions

View File

@ -86,11 +86,15 @@ class Request(dict):
:return: token related to request
"""
prefixes = ('Token ', 'Bearer ')
auth_header = self.headers.get('Authorization')
if auth_header is not None and 'Token ' in auth_header:
return auth_header.partition('Token ')[-1]
else:
return auth_header
if auth_header is not None:
for prefix in prefixes:
if prefix in auth_header:
return auth_header.partition(prefix)[-1]
return auth_header
@property
def form(self):

View File

@ -180,6 +180,16 @@ def test_token():
request, response = app.test_client.get('/', headers=headers)
assert request.token == token
token = 'a1d895e0-553a-421a-8e22-5ff8ecb48cbf'
headers = {
'content-type': 'application/json',
'Authorization': 'Bearer {}'.format(token)
}
request, response = app.test_client.get('/', headers=headers)
assert request.token == token
# no Authorization headers