Refactored Bootstrap::identity() to use IdentityServices::isExpired().

This commit is contained in:
Technosophos
2012-06-12 12:18:11 -05:00
parent 0ff6212c16
commit 9731456945

View File

@@ -133,7 +133,7 @@ class Bootstrap {
/** /**
* An identity services object created from the global settings. * An identity services object created from the global settings.
* @var [type] * @var object HPCloud::Services::IdentityServices
*/ */
public static $identity = NULL; public static $identity = NULL;
@@ -340,18 +340,7 @@ class Bootstrap {
public static function identity($force = FALSE) { public static function identity($force = FALSE) {
// If we already have an identity make sure the token is not expired. // If we already have an identity make sure the token is not expired.
$expired = FALSE; if ($force || is_null(self::$identity) || self::$identity->isExpired()) {
if (!is_null(self::$identity)) {
// Make sure the token we have is not expired.
$tokenDetails = self::$identity->tokenDetails();
$tokenExpires = new \DateTime($tokenDetails['expires']);
$currentDateTime = new \DateTime('now');
if ($currentDateTime > $tokenExpires) {
$expired = TRUE;
}
}
if (is_null(self::$identity) || $expired || $force) {
// Make sure we have an endpoint to use // Make sure we have an endpoint to use
if (!self::hasConfig('endpoint')) { if (!self::hasConfig('endpoint')) {