Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/OpenCloud/OpenStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ public function getUser()
*/
public function authenticate()
{
// OpenStack APIs will return a 401 if an expired X-Auth-Token is sent,
// so we need to reset the value before authenticating for another one.
$this->updateTokenHeader('');

$identity = IdentityService::factory($this);
$response = $identity->generateToken($this->getCredentials());

Expand All @@ -384,7 +388,7 @@ public function authenticate()
}

// Set X-Auth-Token HTTP request header
$this->updateTokenHeader();
$this->updateTokenHeader($this->getToken());
}

/**
Expand Down Expand Up @@ -422,7 +426,7 @@ public function importCredentials(array $values)
{
if (!empty($values['token'])) {
$this->setToken($values['token']);
$this->updateTokenHeader();
$this->updateTokenHeader($this->getToken());
}
if (!empty($values['expiration'])) {
$this->setExpiration($values['expiration']);
Expand All @@ -438,13 +442,12 @@ public function importCredentials(array $values)
/**
* Sets the X-Auth-Token header. If no value is explicitly passed in, the current token is used.
*
* @param string $token Optional value of token.
* @param string $token Value of header.
* @return void
*/
private function updateTokenHeader($token = null)
private function updateTokenHeader($token)
{
$token = $token ? : $this->getToken();
$this->setDefaultOption('headers/X-Auth-Token', (string)$token);
$this->setDefaultOption('headers/X-Auth-Token', (string) $token);
}

/**
Expand Down