def authenticate_token(self, authc_token=None): if authc_token: subject = Yosai.get_current_subject() try: subject.login(authc_token) except: logger.debug_exception('Login failed') raise user = subject.primary_identifier logger.debug('Login complete for user: {}'.format(user)) if isinstance(user, IdentityContext): return user else: # Simple account lookup to ensure the context identity is complete try: logger.debug('Loading identity context from username: {}'.format(user)) with session_scope() as db_session: idp = self._idp_factory.for_session(db_session) identity, _ = idp.lookup_user(user) logger.debug('Authc complete for user: {}'.format(user)) return identity except: logger.debug_exception('Error looking up account for authenticated user') return None else: logger.debug('Anon auth complete') return IdentityContext(username=None, user_account=None, user_account_type=None, user_account_state=None)
def authenticate(self, request): logger.debug('Authenticating with native auth handler') subject = Yosai.get_current_subject() if request.authorization: authc_token = UsernamePasswordToken( username=request.authorization.username, password=request.authorization.password, remember_me=False) subject.login(authc_token) user = subject.primary_identifier # Simple account lookup to ensure the context identity is complete try: with session_scope() as db_session: idp = self._idp_factory.for_session(db_session) identity, _ = idp.lookup_user(user) logger.debug('Authc complete') return identity except: logger.exception( 'Error looking up account for authenticated user') return None else: logger.debug('Anon auth complete') return IdentityContext(username=None, user_account=None, user_account_type=None, user_account_active=None)