def use_refresh_token(self, refresh_token, scope=None):
        # type (str, Optional[List[str]]) -> Tuple[se_leg_op.access_token.AccessToken, Optional[str]]
        """
        Creates a new access token, and refresh token, based on the supplied refresh token.
        :return: new access token and new refresh token if the old one had an expiration time
        """

        if refresh_token not in self.refresh_tokens:
            raise InvalidRefreshToken('{} unknown'.format(refresh_token))

        refresh_token_info = self.refresh_tokens[refresh_token]
        if 'exp' in refresh_token_info and refresh_token_info['exp'] < int(time.time()):
            raise InvalidRefreshToken('{} has expired'.format(refresh_token))

        authz_info = self.access_tokens[refresh_token_info['access_token']]

        if scope:
            if not requested_scope_is_allowed(scope, authz_info['granted_scope']):
                logger.debug('trying to refresh token with superset scope, requested_scope=%s, granted_scope=%s',
                             scope, authz_info['granted_scope'])
                raise InvalidScope('Requested scope includes non-granted value')
            scope = ' '.join(scope)
            logger.debug('refreshing token with new scope, old_scope=%s -> new_scope=%s', authz_info['scope'], scope)
        else:
            # OAuth 2.0: scope: "[...] if omitted is treated as equal to the scope originally granted by the resource owner"
            scope = authz_info['granted_scope']

        new_access_token = self._create_access_token(authz_info['sub'], authz_info[self.KEY_AUTHORIZATION_REQUEST],
                                                     authz_info['granted_scope'], scope)

        new_refresh_token = None
        if self.refresh_token_threshold \
                and 'exp' in refresh_token_info \
                and refresh_token_info['exp'] - int(time.time()) < self.refresh_token_threshold:
            # refresh token is close to expiry, issue a new one
            new_refresh_token = self.create_refresh_token(new_access_token.value)
        else:
            self.refresh_tokens[refresh_token]['access_token'] = new_access_token.value

        logger.debug('refreshed tokens, new_access_token=%s new_refresh_token=%s old_refresh_token=%s',
                     new_access_token, new_refresh_token, refresh_token)
        return new_access_token, new_refresh_token
def use_refresh_token ( self , refresh_token , scope = None ) : if refresh_token not in self . refresh_tokens : raise InvalidRefreshToken ( '{} unknown' . format ( refresh_token ) ) refresh_token_info = self . refresh_tokens [ refresh_token ] if 'exp' in refresh_token_info and refresh_token_info [ 'exp' ] < int ( time . time ( ) ) : raise InvalidRefreshToken ( '{} has expired' . format ( refresh_token ) ) authz_info = self . access_tokens [ refresh_token_info [ 'access_token' ] ] if scope : if not requested_scope_is_allowed ( scope , authz_info [ 'granted_scope' ] ) : logger . debug ( 'trying to refresh token with superset scope, requested_scope=%s, granted_scope=%s' , scope , authz_info [ 'granted_scope' ] ) raise InvalidScope ( 'Requested scope includes non-granted value' ) scope = ' ' . join ( scope ) logger . debug ( 'refreshing token with new scope, old_scope=%s -> new_scope=%s' , authz_info [ 'scope' ] , scope ) else : scope = authz_info [ 'granted_scope' ] new_access_token = self . _create_access_token ( authz_info [ 'sub' ] , authz_info [ self . KEY_AUTHORIZATION_REQUEST ] , authz_info [ 'granted_scope' ] , scope ) new_refresh_token = None if self . refresh_token_threshold and 'exp' in refresh_token_info and refresh_token_info [ 'exp' ] - int ( time . time ( ) ) < self . refresh_token_threshold : new_refresh_token = self . create_refresh_token ( new_access_token . value ) else : self . refresh_tokens [ refresh_token ] [ 'access_token' ] = new_access_token . value logger . debug ( 'refreshed tokens, new_access_token=%s new_refresh_token=%s old_refresh_token=%s' , new_access_token , new_refresh_token , refresh_token ) return new_access_token , new_refresh_token
Creates a new access token, and refresh token, based on the supplied refresh token.
        :return: new access token and new refresh token if the old one had an expiration time