'Delete all tokens in one session.
The user_id will be ignored if the trust_id is specified. user_id
will always be specified.
If using a trust, the token\'s user_id is set to the trustee\'s user ID
or the trustor\'s user ID, so will use trust_id to query the tokens.'

def delete_tokens(self, user_id, tenant_id=None, trust_id=None, consumer_id=None):

    token_list = []
    with sql.session_for_write() as session:
        now = timeutils.utcnow()
        query = session.query(TokenModel)
        query = query.filter_by(valid=True)
        query = query.filter((TokenModel.expires > now))
        if trust_id:
            query = query.filter((TokenModel.trust_id == trust_id))
        else:
            query = query.filter((TokenModel.user_id == user_id))
        for token_ref in query.all():
            if tenant_id:
                token_ref_dict = token_ref.to_dict()
                if (not self._tenant_matches(tenant_id, token_ref_dict)):
                    continue
            if consumer_id:
                token_ref_dict = token_ref.to_dict()
                if (not self._consumer_matches(consumer_id, token_ref_dict)):
                    continue
            token_ref.valid = False
            token_list.append(token_ref.id)
    return token_list
