@ndb.tasklet
  def get_token_async(self, refresh=False):
    if self.token is not None and not refresh:
      raise ndb.Return(self.token)
    key = '%s,%s' % (self.service_account_id, ','.join(self.scopes))
    ts = None
    if not refresh:
      ts = yield _AE_TokenStorage_.get_by_id_async(
          key, use_cache=True, use_memcache=True,
          use_datastore=self.retry_params.save_access_token)
    if ts is None or ts.expires < (time.time() + 60):
      token, expires_at = yield self.make_token_async(
          self.scopes, self.service_account_id)
      timeout = int(expires_at - time.time())
      ts = _AE_TokenStorage_(id=key, token=token, expires=expires_at)
      if timeout > 0:
        yield ts.put_async(memcache_timeout=timeout,
                           use_datastore=self.retry_params.save_access_token,
                           use_cache=True, use_memcache=True)
    self.token = ts.token
    raise ndb.Return(self.token)
Get an authentication token.
dataset/ETHPy150Open GoogleCloudPlatform/billing-export-python/cloudstorage/rest_api.py/_RestApi.get_token_async