Skip to content

Commit

Permalink
Added the ability to set the name of the header used for authenticati…
Browse files Browse the repository at this point in the history
…on to support ChilliProject (and any other ticketing system) that may use Redmine but authenticate with a different header.
  • Loading branch information
nerdo committed Apr 30, 2014
1 parent 428d365 commit 7c74f94
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/Redmine/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Client
*/
private $apikeyOrUsername;

/**
* @var string
*/
private $apikeyHeaderName = 'X-Redmine-API-Key';

/**
* @var string or null
*/
Expand Down Expand Up @@ -255,6 +260,27 @@ public function setPort($port = null)
return $this;
}

/**
* Set the name of the HTTP header used to set the API key for authentication
* @param string $name
* @return Client
*/
public function setApikeyHeaderName($name = null) {
if (null !== $name) {
$this->apikeyHeaderName = $name;
}

return $this;
}

/**
* Returns the name of the HTTP header used to set the API key for authentication
* @return string
*/
public function getApikeyHeaderName() {
return $this->apikeyHeaderName;
}

/**
* Returns Redmine response code
* @return int
Expand Down Expand Up @@ -335,7 +361,7 @@ private function runRequest($path, $method = 'GET', $data = '')

if (!empty($httpHeader)) {
if (null === $this->pass) {
$httpHeader[] = 'X-Redmine-API-Key: '.$this->apikeyOrUsername;
$httpHeader[] = $this->apikeyHeaderName.': '.$this->apikeyOrUsername;
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeader);
}
Expand Down

0 comments on commit 7c74f94

Please sign in to comment.