protected function initializeObjectStorage() {

    $token = $this->cxt('token');

    $account = $this->cxt('account');
    // Legacy support for old 'key' param.
    $key = $this->cxt('key', $this->cxt('secret'));

    $tenantId = $this->cxt('tenantid');
    $tenantName = $this->cxt('tenantname');
    $authUrl = $this->cxt('endpoint');
    $endpoint = $this->cxt('swift_endpoint');
    $region = $this->cxt('region');

    $serviceCatalog = NULL;

    if (!empty($token) && isset(self::$serviceCatalogCache[$token])) {
      $serviceCatalog = self::$serviceCatalogCache[$token];
    }

    // FIXME: If a token is invalidated, we should try to re-authenticate.
    // If context has the info we need, start from there.
    if (!empty($token) && !empty($endpoint)) {
      $this->store = new \HPCloud\Storage\ObjectStorage($token, $endpoint);
    }
    // DEPRECATED: For old swift auth.
    elseif ($this->cxt('use_swift_auth', FALSE)) {
      if (empty($authUrl) || empty($account) || empty($key)) {
        throw new \HPCloud\Exception('account, endpoint, key are required stream parameters.');
      }
      $this->store = \HPCloud\Storage\ObjectStorage::newFromSwiftAuth($account, $key, $authUrl);

    }
    // If we get here and tenant ID is not set, we can't get a container.
    elseif (empty($tenantId) && empty($tenantName)) {
      throw new \HPCloud\Exception('Either Tenant ID (tenantid) or Tenant Name (tenantname) is required.');
    }
    elseif (empty($authUrl)) {
      throw new \HPCloud\Exception('An Identity Service Endpoint (endpoint) is required.');
    }
    // Try to authenticate and get a new token.
    else {
      $ident = $this->authenticate();

      // Update token and service catalog. The old pair may be out of date.
      $token = $ident->token();
      $serviceCatalog = $ident->serviceCatalog();
      self::$serviceCatalogCache[$token] = $serviceCatalog;

      $this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token, $region);

      /*
      $catalog = $ident->serviceCatalog(ObjectStorage::SERVICE_TYPE);
      if (empty($catalog) || empty($catalog[0]['endpoints'][0]['publicURL'])) {
        //throw new \HPCloud\Exception('No object storage services could be found for this tenant ID.' . print_r($catalog, TRUE));
        throw new \HPCloud\Exception('No object storage services could be found for this tenant ID.');
      }
      $serviceURL = $catalog[0]['endpoints'][0]['publicURL'];

      $this->store = new ObjectStorage($token, $serviceURL);
       */
    }

    try {
      $this->initializeCDN($token, $serviceCatalog);
    }
    catch (\HPCloud\Exception $e) {
      //fwrite(STDOUT, $e);
      throw new \HPCloud\Exception('CDN could not be initialized', 1, $e);

    }

    return !empty($this->store);

  }