Skip to content

Commit

Permalink
Merge pull request #57 from bradstinson/master
Browse files Browse the repository at this point in the history
Added support for digest authentication
  • Loading branch information
nategood committed Oct 6, 2012
2 parents e1ba467 + c27b9b7 commit 6db93c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public function hasBasicAuth()
return isset($this->password) && isset($this->username);
}

/**
* @return bool Is this request setup for digest auth?
*/
public function hasDigestAuth()
{
return isset($this->password) && isset($this->username) && $this->additional_curl_opts['CURLOPT_HTTPAUTH'] = CURLAUTH_DIGEST;
}

/**
* If the response is a 301 or 302 redirect, automatically
* send off another request to that location
Expand Down Expand Up @@ -221,6 +229,24 @@ public function authenticateWithBasic($username, $password)
return $this->basicAuth($username, $password);
}

/**
* User Digest Auth.
* @return Request this
* @param string $username
* @param string $password
*/
public function digestAuth($username, $password)
{
$this->addOnCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
return $this->basicAuth($username, $password);
}

// @alias of digestAuth
public function authenticateWithDigest($username, $password)
{
return $this->digestAuth($username, $password);
}

/**
* @return is this request setup for client side cert?
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/Httpful/HttpfulTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ function testAuthSetup()
$this->assertTrue($r->hasBasicAuth());
}

function testDigestAuthSetup()
{
$username = 'nathan';
$password = 'opensesame';

$r = Request::get('http://example.com/')
->authenticateWithDigest($username, $password);

$this->assertEquals($username, $r->username);
$this->assertEquals($password, $r->password);
$this->assertTrue($r->hasDigestAuth());
}

function testJsonResponseParse()
{
$req = Request::init()->sendsAndExpects(Mime::JSON);
Expand Down

0 comments on commit 6db93c1

Please sign in to comment.