This returns the number of seconds this association is still
valid for, or 0 if the association is no longer valid.
public getExpiresIn ( $now = null ) : integer | ||
리턴 | integer | $seconds The number of seconds this association is still valid for, or 0 if the association is no longer valid. |
/** * Get an association * * @param string $server_url The identity server endpoint * @param string $handle The association handle * @return Auth_OpenID_Association */ public function getAssociation($server_url, $handle = null) { $assocs = $this->getAssociations($server_url, $handle); if (!$assocs || count($assocs) == 0) { return null; } else { $associations = array(); foreach ($assocs as $object) { $assoc = new Auth_OpenID_Association($object->handle, base64_decode($object->secret), $object->issued, $object->lifetime, $object->assoc_type); if ($assoc->getExpiresIn() == 0) { $this->removeAssociation($server_url, $assoc->handle); } else { $associations[] = array($assoc->issued, $assoc); } } if ($associations) { $issued = array(); $assocs = array(); foreach ($associations as $key => $assoc) { $issued[$key] = $assoc[0]; $assocs[$key] = $assoc[1]; } array_multisort($issued, SORT_DESC, $assocs, SORT_DESC, $associations); // return the most recently issued one. list($issued, $assoc) = $associations[0]; return $assoc; } else { return null; } } }
function getAssociation($server_url, $handle = null) { if (isset($handle)) { $meta_array = array('server_url' => $server_url, 'handle' => $handle); $assocs = elgg_get_entities_from_metadata(array('metadata_name_value_pairs' => $meta_array, 'types' => 'object', 'subtypes' => 'openid_client::association', 'metadata_name_value_pairs_operator' => 'and')); } else { $assocs = elgg_get_entities_from_metadata(array('metadata_names' => 'server_url', 'metadata_values' => $server_url, 'types' => 'object', 'subtypes' => 'openid_client::association', 'metadata_case_sensitive' => FALSE)); } if (!$assocs || count($assocs) == 0) { return null; } else { $associations = array(); foreach ($assocs as $assoc_row) { $assoc = new Auth_OpenID_Association($assoc_row->handle, base64_decode($assoc_row->secret), $assoc_row->issued, $assoc_row->lifetime, $assoc_row->assoc_type); if ($assoc->getExpiresIn() == 0) { OpenIDServer_ElggStore::removeAssociation($server_url, $assoc->handle); } else { $associations[] = array($assoc->issued, $assoc); } } if ($associations) { $issued = array(); $assocs = array(); foreach ($associations as $key => $assoc) { $issued[$key] = $assoc[0]; $assocs[$key] = $assoc[1]; } array_multisort($issued, SORT_DESC, $assocs, SORT_DESC, $associations); // return the most recently issued one. list($issued, $assoc) = $associations[0]; return $assoc; } else { return null; } } }
function getAssociation($server_url, $handle = null) { if ($handle !== null) { $assoc = $this->_get_assoc($server_url, $handle); $assocs = array(); if ($assoc) { $assocs[] = $assoc; } } else { $assocs = $this->_get_assocs($server_url); } if (!$assocs || count($assocs) == 0) { return null; } else { $associations = array(); foreach ($assocs as $assoc_row) { $assoc = new Auth_OpenID_Association($assoc_row['handle'], $assoc_row['secret'], $assoc_row['issued'], $assoc_row['lifetime'], $assoc_row['assoc_type']); $assoc->secret = $this->blobDecode($assoc->secret); if ($assoc->getExpiresIn() == 0) { $this->removeAssociation($server_url, $assoc->handle); } else { $associations[] = array($assoc->issued, $assoc); } } if ($associations) { $issued = array(); $assocs = array(); foreach ($associations as $key => $assoc) { $issued[$key] = $assoc[0]; $assocs[$key] = $assoc[1]; } array_multisort($issued, SORT_DESC, $assocs, SORT_DESC, $associations); // return the most recently issued one. list($issued, $assoc) = $associations[0]; return $assoc; } else { return null; } } }
function test_expiredAssoc() { // Store an expired association for the server with the handle // that is in the query $issued = time() - 10; $lifetime = 0; $handle = 'handle'; $assoc = new Auth_OpenID_Association($handle, 'secret', $issued, $lifetime, 'HMAC-SHA1'); $this->assertTrue($assoc->getExpiresIn() <= 0); $this->store->storeAssociation($this->server_url, $assoc); $query = array('openid.return_to' => $this->return_to, 'openid.identity' => $this->server_id, 'openid.sig' => 'bogus', 'openid.signed' => 'identity,return_to', 'openid.assoc_handle' => $handle); $message = Auth_OpenID_Message::fromPostArgs($query); $this->consumer->disableReturnToChecking(); $info = $this->_doIdRes($message, $this->endpoint, null); $this->assertEquals('failure', $info->status); $this->assertTrue(strpos($info->message, 'expired') !== false); }
function test_expiredAssoc() { // Store an expired association for the server with the handle // that is in the query $issued = time() - 10; $lifetime = 0; $handle = 'handle'; $assoc = new Auth_OpenID_Association($handle, 'secret', $issued, $lifetime, 'HMAC-SHA1'); $this->assertTrue($assoc->getExpiresIn() <= 0); $this->store->storeAssociation($this->server_url, $assoc); $query = array('openid.return_to' => $this->return_to, 'openid.identity' => $this->server_id, 'openid.assoc_handle' => $handle); $info = $this->_doIdRes($query); $this->assertEquals('failure', $info->status); $this->assertEquals($this->consumer_id, $info->identity_url); $this->assertTrue(strpos($info->message, 'expired') !== false); }