@@ -370,6 +370,10 @@ public function getUser()
370
370
*/
371
371
public function authenticate ()
372
372
{
373
+ // OpenStack APIs will return a 401 if an expired X-Auth-Token is sent,
374
+ // so we need to reset the value before authenticating for another one.
375
+ $ this ->updateTokenHeader ('' );
376
+
373
377
$ identity = IdentityService::factory ($ this );
374
378
$ response = $ identity ->generateToken ($ this ->getCredentials ());
375
379
@@ -384,7 +388,7 @@ public function authenticate()
384
388
}
385
389
386
390
// Set X-Auth-Token HTTP request header
387
- $ this ->updateTokenHeader ();
391
+ $ this ->updateTokenHeader ($ this -> getToken () );
388
392
}
389
393
390
394
/**
@@ -422,7 +426,7 @@ public function importCredentials(array $values)
422
426
{
423
427
if (!empty ($ values ['token ' ])) {
424
428
$ this ->setToken ($ values ['token ' ]);
425
- $ this ->updateTokenHeader ();
429
+ $ this ->updateTokenHeader ($ this -> getToken () );
426
430
}
427
431
if (!empty ($ values ['expiration ' ])) {
428
432
$ this ->setExpiration ($ values ['expiration ' ]);
@@ -438,13 +442,12 @@ public function importCredentials(array $values)
438
442
/**
439
443
* Sets the X-Auth-Token header. If no value is explicitly passed in, the current token is used.
440
444
*
441
- * @param string $token Optional value of token .
445
+ * @param string $token Value of header .
442
446
* @return void
443
447
*/
444
- private function updateTokenHeader ($ token = null )
448
+ private function updateTokenHeader ($ token )
445
449
{
446
- $ token = $ token ? : $ this ->getToken ();
447
- $ this ->setDefaultOption ('headers/X-Auth-Token ' , (string )$ token );
450
+ $ this ->setDefaultOption ('headers/X-Auth-Token ' , (string ) $ token );
448
451
}
449
452
450
453
/**
0 commit comments