Added isExpired() to IdentityServices object.
This commit is contained in:
@@ -483,6 +483,31 @@ class IdentityServices {
|
|||||||
return $this->tokenDetails;
|
return $this->tokenDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the current identity has an expired token.
|
||||||
|
*
|
||||||
|
* This does not perform a round-trip to the server. Instead, it compares the
|
||||||
|
* machine's local timestamp with the server's expiration time stamp. A
|
||||||
|
* mis-configured machine timestamp could give spurious results.
|
||||||
|
*
|
||||||
|
* @retval boolean
|
||||||
|
* This will return FALSE if there is a current token and it has
|
||||||
|
* not yet expired (according to the date info). In all other cases
|
||||||
|
* it returns TRUE.
|
||||||
|
*/
|
||||||
|
public function isExpired() {
|
||||||
|
$details = $this->tokenDetails();
|
||||||
|
|
||||||
|
if (empty($details['expires'])) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentDateTime = new \DateTime('now');
|
||||||
|
$expireDateTime = new \DateTime($details['expires']);
|
||||||
|
|
||||||
|
return $currentDateTime > $expireDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the service catalog, optionaly filtering by type.
|
* Get the service catalog, optionaly filtering by type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -170,6 +170,16 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
|
|||||||
$this->assertNotEmpty($service->token());
|
$this->assertNotEmpty($service->token());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAuthenticateAsAccount
|
||||||
|
*/
|
||||||
|
public function testIsExpired($service) {
|
||||||
|
$this->assertFalse($service->isExpired());
|
||||||
|
|
||||||
|
$service2 = new IdentityServices(self::conf('hpcloud.identity.url'));
|
||||||
|
$this->assertTrue($service2->isExpired());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testAuthenticateAsAccount
|
* @depends testAuthenticateAsAccount
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user