/**
  * Initiates authentication with the remote service and returns a
  * array containing the storage system URL, CDN URL (can be empty)
  * and session token.
  *
  * @return array
  * @throws \Exception|\OpenStackStorage\Exceptions\ResponseError
  * @throws \OpenStackStorage\Exceptions\AuthenticationError
  * @throws \OpenStackStorage\Exceptions\AuthenticationFailed
  * @throws \Exception
  */
 public function authenticate()
 {
     $client = new Client(array('timeout' => $this->timeout));
     $client->setBaseURL(sprintf('%s://%s:%d/', $this->urlInfo['scheme'], $this->urlInfo['host'], $this->urlInfo['port']));
     $client->setUserAgent($this->userAgent);
     try {
         $response = $client->get($this->urlInfo['path'], null, $this->headers);
     } catch (Exceptions\ResponseError $e) {
         if (401 == $e->getCode()) {
             // A status code of 401 indicates that the supplied credentials
             // were not accepted by the authentication service.
             throw new Exceptions\AuthenticationFailed();
         }
         throw $e;
     }
     if (isset($response['headers']['x-auth-token'])) {
         $authToken = $response['headers']['x-auth-token'];
     } elseif (isset($response['headers']['x-storage-token'])) {
         $authToken = $response['headers']['x-storage-token'];
     } else {
         $authToken = null;
     }
     if (isset($response['headers']['x-storage-url'])) {
         $storageUrl = $response['headers']['x-storage-url'];
     } else {
         $storageUrl = null;
     }
     if (!($authToken && $storageUrl)) {
         throw new Exceptions\AuthenticationError('Invalid response from the authentication service.');
     }
     if (isset($response['headers']['x-cdn-management-url'])) {
         $cdnUrl = $response['headers']['x-cdn-management-url'];
     } else {
         $cdnUrl = null;
     }
     return array($storageUrl, $cdnUrl, $authToken);
 }