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)
|
||||
|
||||
|
||||
def process_basic_auth():
|
||||
auth = request.headers.get('authorization', '')
|
||||
def process_basic_auth(auth):
|
||||
normalized = [part.strip() for part in auth.split(' ') if part]
|
||||
if normalized[0].lower() != 'basic' or len(normalized) != 2:
|
||||
logger.debug('Invalid basic auth format.')
|
||||
|
@ -50,10 +49,7 @@ def process_basic_auth():
|
|||
abort(401)
|
||||
|
||||
|
||||
def process_token():
|
||||
auth = request.headers.get('authorization', '')
|
||||
logger.debug('Validating auth token: %s' % auth)
|
||||
|
||||
def process_token(auth):
|
||||
normalized = [part.strip() for part in auth.split(' ') if part]
|
||||
if normalized[0].lower() != 'token' or len(normalized) != 2:
|
||||
logger.debug('Invalid token format.')
|
||||
|
@ -97,8 +93,15 @@ def process_token():
|
|||
def process_auth(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
process_token()
|
||||
process_basic_auth()
|
||||
auth = request.headers.get('authorization', '')
|
||||
|
||||
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 wrapper
|
||||
|
||||
|
|
Reference in a new issue