def session(self) -> str:
        """ Generate a session(authorization Bearer) JWT token """
        session_jwt = None
        self.user = self.user_model.where_username(self.username)
        if self.user is None:
            return None
        self.user.updated()  # update timestamp on user access
        if self.verify_password(self.user.password):
            session_id = Session.create_session_id()
            data = {
                'session_id': session_id,
                'user_id': self.user.id,
                'user_email': self.user.email,
            }
            token_valid_for = \
                current_app.config['AUTH']['JWT']['TOKENS']['VALID_FOR'] if \
                'VALID_FOR' in \
                current_app.config['AUTH']['JWT']['TOKENS'] else 180
            if current_app.config['AUTH']['JWT']['REFRESH_TOKENS']['ENABLED']:
                refresh_token_valid_for = \
                    current_app \
                    .config['AUTH']['JWT']['REFRESH_TOKENS']['VALID_FOR'] if \
                    'VALID_FOR' in \
                    current_app.config['AUTH']['JWT']['REFRESH_TOKENS'] else \
                    86400
                session_jwt = JWT().create_token_with_refresh_token(
                    data,
                    token_valid_for,
                    refresh_token_valid_for)
            else:
                session_jwt = JWT().create_token(data, token_valid_for)
            Session.create_session(session_id, self.user.id)
            return session_jwt
        return None
def session ( self ) -> str : session_jwt = None self . user = self . user_model . where_username ( self . username ) if self . user is None : return None self . user . updated ( ) if self . verify_password ( self . user . password ) : session_id = Session . create_session_id ( ) data = { 'session_id' : session_id , 'user_id' : self . user . id , 'user_email' : self . user . email , } token_valid_for = current_app . config [ 'AUTH' ] [ 'JWT' ] [ 'TOKENS' ] [ 'VALID_FOR' ] if 'VALID_FOR' in current_app . config [ 'AUTH' ] [ 'JWT' ] [ 'TOKENS' ] else 180 if current_app . config [ 'AUTH' ] [ 'JWT' ] [ 'REFRESH_TOKENS' ] [ 'ENABLED' ] : refresh_token_valid_for = current_app . config [ 'AUTH' ] [ 'JWT' ] [ 'REFRESH_TOKENS' ] [ 'VALID_FOR' ] if 'VALID_FOR' in current_app . config [ 'AUTH' ] [ 'JWT' ] [ 'REFRESH_TOKENS' ] else 86400 session_jwt = JWT ( ) . create_token_with_refresh_token ( data , token_valid_for , refresh_token_valid_for ) else : session_jwt = JWT ( ) . create_token ( data , token_valid_for ) Session . create_session ( session_id , self . user . id ) return session_jwt return None
Generate a session(authorization Bearer) JWT token