Handle the case where there is no auth at all.
This commit is contained in:
parent
2a9a8635b6
commit
0652636693
1 changed files with 11 additions and 8 deletions
19
auth/auth.py
19
auth/auth.py
|
@ -22,8 +22,7 @@ def get_validated_token():
|
||||||
return getattr(_request_ctx_stack.top, 'validated_token', None)
|
return getattr(_request_ctx_stack.top, 'validated_token', None)
|
||||||
|
|
||||||
|
|
||||||
def process_basic_auth():
|
def process_basic_auth(auth):
|
||||||
auth = request.headers.get('authorization', '')
|
|
||||||
normalized = [part.strip() for part in auth.split(' ') if part]
|
normalized = [part.strip() for part in auth.split(' ') if part]
|
||||||
if normalized[0].lower() != 'basic' or len(normalized) != 2:
|
if normalized[0].lower() != 'basic' or len(normalized) != 2:
|
||||||
logger.debug('Invalid basic auth format.')
|
logger.debug('Invalid basic auth format.')
|
||||||
|
@ -50,10 +49,7 @@ def process_basic_auth():
|
||||||
abort(401)
|
abort(401)
|
||||||
|
|
||||||
|
|
||||||
def process_token():
|
def process_token(auth):
|
||||||
auth = request.headers.get('authorization', '')
|
|
||||||
logger.debug('Validating auth token: %s' % auth)
|
|
||||||
|
|
||||||
normalized = [part.strip() for part in auth.split(' ') if part]
|
normalized = [part.strip() for part in auth.split(' ') if part]
|
||||||
if normalized[0].lower() != 'token' or len(normalized) != 2:
|
if normalized[0].lower() != 'token' or len(normalized) != 2:
|
||||||
logger.debug('Invalid token format.')
|
logger.debug('Invalid token format.')
|
||||||
|
@ -97,8 +93,15 @@ def process_token():
|
||||||
def process_auth(f):
|
def process_auth(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
process_token()
|
auth = request.headers.get('authorization', '')
|
||||||
process_basic_auth()
|
|
||||||
|
if auth:
|
||||||
|
logger.debug('Validating auth header: %s' % auth)
|
||||||
|
process_token(auth)
|
||||||
|
process_basic_auth(auth)
|
||||||
|
else:
|
||||||
|
logger.debug('No auth header.')
|
||||||
|
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
Reference in a new issue