Skip to content

Commit

Permalink
Added digest auth support
Browse files Browse the repository at this point in the history
support for

Added support for digest authentication and included required unit
tests.
  • Loading branch information
bradstinson committed Sep 25, 2012
1 parent c678733 commit c27b9b7
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 @@ -131,6 +131,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 @@ -219,6 +227,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 c27b9b7

Please sign in to comment.