async def __authorize_when_necessary(self, token_params=None, auth_options=None, force=False):
    self.__auth_mechanism = Auth.Method.TOKEN
    if (token_params is None):
        token_params = dict(self.auth_options.default_token_params)
    else:
        self.auth_options.default_token_params = dict(token_params)
        self.auth_options.default_token_params.pop('timestamp', None)
    if (auth_options is not None):
        self.auth_options.replace(auth_options)
    auth_options = dict(self.auth_options.auth_options)
    if (self.client_id is not None):
        token_params['client_id'] = self.client_id
    token_details = self.__token_details
    if ((not force) and (not self.token_details_has_expired())):
        log.debug('using cached token; expires = %d', token_details.expires)
        return token_details
    self.__token_details = (await self.request_token(token_params, **auth_options))
    self._configure_client_id(self.__token_details.client_id)
    return self.__token_details
async def __authorize_when_necessary(self, token_params=None, auth_options=None, force=False):
    self.__auth_mechanism = Auth.Method.TOKEN
    if (token_params is None):
        token_params = dict(self.auth_options.default_token_params)
    else:
        self.auth_options.default_token_params = dict(token_params)
        self.auth_options.default_token_params.pop('timestamp', None)
    if (auth_options is not None):
        self.auth_options.replace(auth_options)
    auth_options = dict(self.auth_options.auth_options)
    if (self.client_id is not None):
        token_params['client_id'] = self.client_id
    token_details = self.__token_details
    if ((not force) and (not self.token_details_has_expired())):
        log.debug('using cached token; expires = %d', token_details.expires)
        return token_details
    self.__token_details = (await self.request_token(token_params, **auth_options))
    self._configure_client_id(self.__token_details.client_id)
    return self.__token_details