diff --git a/pillar/api/utils/authentication.py b/pillar/api/utils/authentication.py index fb83f125..86b6f1a0 100644 --- a/pillar/api/utils/authentication.py +++ b/pillar/api/utils/authentication.py @@ -113,7 +113,7 @@ def validate_token(): @returns True iff the user is logged in with a valid Blender ID token. """ - from pillar.auth import force_logout_user + from pillar.auth import AnonymousUser if request.authorization: token = request.authorization.username @@ -131,7 +131,7 @@ def validate_token(): # If no authorization headers are provided, we are getting a request # from a non logged in user. Proceed accordingly. log.debug('No authentication headers, so not logged in.') - force_logout_user() + g.current_user = AnonymousUser() return False return validate_this_token(token, oauth_subclient) is not None @@ -144,9 +144,9 @@ def validate_this_token(token, oauth_subclient=None): :rtype: dict """ - from pillar.auth import UserClass, force_logout_user + from pillar.auth import UserClass, AnonymousUser - force_logout_user() + g.current_user = None _delete_expired_tokens() # Check the users to see if there is one with this Blender ID token. @@ -168,6 +168,7 @@ def validate_this_token(token, oauth_subclient=None): if db_user is None: log.debug('Validation failed, user not logged in') + g.current_user = AnonymousUser() return None g.current_user = UserClass.construct(token, db_user) diff --git a/pillar/auth/__init__.py b/pillar/auth/__init__.py index b4b5d0ad..429e384b 100644 --- a/pillar/auth/__init__.py +++ b/pillar/auth/__init__.py @@ -207,21 +207,6 @@ def login_user(oauth_token: str, *, load_from_db=False): g.current_user = user -def force_logout_user(): - """Resets the current user to an AnonymousUser instance.""" - - from flask import g - - # Force the current user to be the anonymous user. Calling - # flask_login.logout_user() here would cause infinite recursion, because - # that calls _load_user(), which in turn tries to validate the current - # token, which in turn starts by calling force_logout_user() just to be - # safe. - anon_user = AnonymousUser() - flask_login.current_user = anon_user - g.current_user = anon_user - - def get_blender_id_oauth_token(): """Returns a tuple (token, ''), for use with flask_oauthlib."""