/**
  * Authentication API
  *
  * @param  string $username
  * @param  string $password
  * @param  string $key
  * @return bool
  */
 protected function auth($username, $password, $key = null)
 {
     if (empty($key)) {
         $result = $this->api->authenticate($username, $password);
     } else {
         $result = $this->api->authenticateByKey($username, $key);
     }
     if ($this->api->isSuccess()) {
         if (isset($result['access']['token']['id'])) {
             $this->token = $result['access']['token']['id'];
             $this->api->setHeaders(array(self::HEADER_AUTHTOKEN => $this->token));
             $this->services = $result['access']['serviceCatalog'];
             return true;
         }
     }
     return false;
 }