protected function authenticate()
    {
        // Check if the enough attributes have been set to perform authentication.
        // Note that password is not required by all methods.
        if (empty($this->username) || empty($this->authMethod)) {
            throw new ConfigurationException(
                sprintf(
                    'Missing authentication parameters. Method: "%s", username "%s".',
                    $this->authMethod,
                    $this->username
                )
            );
        }

        // Make sure a valid authentication method has been set.
        $authMethodMap = array(
            'http-token' => Client::AUTH_HTTP_TOKEN,
            'password' => Client::AUTH_HTTP_PASSWORD,
            'client-id' => Client::AUTH_URL_CLIENT_ID,
            'url-token' => Client::AUTH_URL_TOKEN,
        );
        if (!isset($authMethodMap[$this->authMethod])) {
            throw new ConfigurationException(
                sprintf(
                    'Unknown authentication method "%s". Supported methods "%s"',
                    $this->authMethod,
                    implode('", "', array_keys($authMethodMap))
                )
            );
        }

        // Set authentication.
        $this->client->authenticate($this->username, $this->password, $authMethodMap[$this->authMethod]);
    }