async def create_token_request(self, token_params=None, key_name=None, key_secret=None, query_time=None):
    token_params = (token_params or {})
    token_request = {}
    key_name = (key_name or self.auth_options.key_name)
    key_secret = (key_secret or self.auth_options.key_secret)
    if ((not key_name) or (not key_secret)):
        log.debug('key_name or key_secret blank')
        raise AblyException('No key specified: no means to generate a token', 401, 40101)
    token_request['key_name'] = key_name
    if token_params.get('timestamp'):
        token_request['timestamp'] = token_params['timestamp']
    else:
        if (query_time is None):
            query_time = self.auth_options.query_time
        if query_time:
            if (self.__time_offset is None):
                server_time = (await self.ably.time())
                local_time = self._timestamp()
                self.__time_offset = (server_time - local_time)
                token_request['timestamp'] = server_time
            else:
                local_time = self._timestamp()
                token_request['timestamp'] = (local_time + self.__time_offset)
        else:
            token_request['timestamp'] = self._timestamp()
    token_request['timestamp'] = int(token_request['timestamp'])
    ttl = token_params.get('ttl')
    if (ttl is not None):
        if isinstance(ttl, timedelta):
            ttl = (ttl.total_seconds() * 1000)
        token_request['ttl'] = int(ttl)
    capability = token_params.get('capability')
    if (capability is not None):
        token_request['capability'] = str(Capability(capability))
    token_request['client_id'] = (token_params.get('client_id') or self.client_id)
    token_request['nonce'] = (token_params.get('nonce') or self._random_nonce())
    token_request = TokenRequest(**token_request)
    if (token_params.get('mac') is None):
        token_request.sign_request(key_secret.encode('utf8'))
    else:
        token_request.mac = token_params['mac']
    return token_request
async def create_token_request(self, token_params=None, key_name=None, key_secret=None, query_time=None):
    token_params = (token_params or {})
    token_request = {}
    key_name = (key_name or self.auth_options.key_name)
    key_secret = (key_secret or self.auth_options.key_secret)
    if ((not key_name) or (not key_secret)):
        log.debug('key_name or key_secret blank')
        raise AblyException('No key specified: no means to generate a token', 401, 40101)
    token_request['key_name'] = key_name
    if token_params.get('timestamp'):
        token_request['timestamp'] = token_params['timestamp']
    else:
        if (query_time is None):
            query_time = self.auth_options.query_time
        if query_time:
            if (self.__time_offset is None):
                server_time = (await self.ably.time())
                local_time = self._timestamp()
                self.__time_offset = (server_time - local_time)
                token_request['timestamp'] = server_time
            else:
                local_time = self._timestamp()
                token_request['timestamp'] = (local_time + self.__time_offset)
        else:
            token_request['timestamp'] = self._timestamp()
    token_request['timestamp'] = int(token_request['timestamp'])
    ttl = token_params.get('ttl')
    if (ttl is not None):
        if isinstance(ttl, timedelta):
            ttl = (ttl.total_seconds() * 1000)
        token_request['ttl'] = int(ttl)
    capability = token_params.get('capability')
    if (capability is not None):
        token_request['capability'] = str(Capability(capability))
    token_request['client_id'] = (token_params.get('client_id') or self.client_id)
    token_request['nonce'] = (token_params.get('nonce') or self._random_nonce())
    token_request = TokenRequest(**token_request)
    if (token_params.get('mac') is None):
        token_request.sign_request(key_secret.encode('utf8'))
    else:
        token_request.mac = token_params['mac']
    return token_request