From 0652636693bb42626b7f30b913bbba87efc8aafe Mon Sep 17 00:00:00 2001 From: yackob03 Date: Tue, 1 Oct 2013 00:37:28 -0400 Subject: [PATCH] Handle the case where there is no auth at all. --- auth/auth.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/auth/auth.py b/auth/auth.py index d0a947d05..1e43c0492 100644 --- a/auth/auth.py +++ b/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