Changeset - d052078e0a16
[Not reviewed]
default
0 1 0
Søren Løvborg - 10 years ago 2015-07-14 13:59:59
kwi@kwi.dk
BaseController: refactor API key authentication

Untangle API key authentication. Creating an AuthUser from an API key
can leave the AuthUser authenticated or not, depending on key validity
and Kallithea configuration; but either way, _determine_auth_user will
not change this fact, and we can return early.
1 file changed with 5 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/base.py
Show inline comments
 
@@ -343,17 +343,19 @@ class BaseController(WSGIController):
 
    def _determine_auth_user(api_key, session_authuser):
 
        """
 
        Create an `AuthUser` object given the IP address of the request, the
 
        API key (if any), and the authuser from the session.
 
        """
 

	
 
        # Authenticate by API key
 
        if api_key:
 
            # when using API_KEY we are sure user exists.
 
            auth_user = AuthUser(api_key=api_key)
 
            authenticated = False
 
        else:
 
            return AuthUser(api_key=api_key)
 

	
 
        # Authenticate by session cookie
 
        if True:
 
            cookie_store = CookieStoreWrapper(session_authuser)
 
            user_id = cookie_store.get('user_id')
 
            try:
 
                auth_user = AuthUser(user_id=user_id)
 
            except UserCreationError as e:
 
                # container auth or other auth functions that create users on
0 comments (0 inline, 0 general)