Set HTTP authorization parameters
string|bool $user User name or false disable authentication:
string $password Password:
string $scheme Authentication scheme to use (Basic, Digest):
Overrides RequestInterface::setAuth
http://www.ietf.org/rfc/rfc2617.txt
public function setAuth($user, $password = '', $scheme = CURLAUTH_BASIC) {
// If we got false or null, disable authentication
if (!$user || !$password) {
$this->password = $this->username = null;
$this
->removeHeader('Authorization');
$this
->getCurlOptions()
->remove(CURLOPT_HTTPAUTH);
}
else {
$this->username = $user;
$this->password = $password;
// Bypass CURL when using basic auth to promote connection reuse
if ($scheme == CURLAUTH_BASIC) {
$this
->getCurlOptions()
->remove(CURLOPT_HTTPAUTH);
$this
->setHeader('Authorization', 'Basic ' . base64_encode($this->username . ':' . $this->password));
}
else {
$this
->getCurlOptions()
->set(CURLOPT_HTTPAUTH, $scheme)
->set(CURLOPT_USERPWD, $this->username . ':' . $this->password);
}
}
return $this;
}