Merge pull request #811 from Frzk/bearer-support
Added support for 'Authorization: Bearer <TOKEN>' header...
This commit is contained in:
commit
dbcbf12456
|
@ -86,10 +86,14 @@ class Request(dict):
|
||||||
|
|
||||||
:return: token related to request
|
:return: token related to request
|
||||||
"""
|
"""
|
||||||
|
prefixes = ('Token ', 'Bearer ')
|
||||||
auth_header = self.headers.get('Authorization')
|
auth_header = self.headers.get('Authorization')
|
||||||
if auth_header is not None and 'Token ' in auth_header:
|
|
||||||
return auth_header.partition('Token ')[-1]
|
if auth_header is not None:
|
||||||
else:
|
for prefix in prefixes:
|
||||||
|
if prefix in auth_header:
|
||||||
|
return auth_header.partition(prefix)[-1]
|
||||||
|
|
||||||
return auth_header
|
return auth_header
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -182,6 +182,16 @@ def test_token():
|
||||||
|
|
||||||
assert request.token == token
|
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
|
# no Authorization headers
|
||||||
headers = {
|
headers = {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user