123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- require_once 'Auth/OpenID/Interface.php';
- class Auth_OpenID_MemcachedStore extends Auth_OpenID_OpenIDStore {
-
- function Auth_OpenID_MemcachedStore($connection, $compress = false)
- {
- $this->connection = $connection;
- $this->compress = $compress ? MEMCACHE_COMPRESSED : 0;
- }
-
- function storeAssociation($server_url, $association)
- {
-
-
- $associationKey = $this->associationKey($server_url,
- $association->handle);
- $serverKey = $this->associationServerKey($server_url);
-
-
- $serverAssociations = $this->connection->get($serverKey);
-
-
- if (!$serverAssociations) {
- $serverAssociations = array();
- }
-
- $serverAssociations[$association->issued] = $associationKey;
-
-
- $this->connection->set(
- $serverKey,
- $serverAssociations,
- $this->compress
- );
-
- $this->connection->set(
- $associationKey,
- $association,
- $this->compress,
- $association->issued + $association->lifetime);
- }
-
- function getAssociation($server_url, $handle = null)
- {
-
- if ($handle !== null) {
-
- $association = $this->connection->get(
- $this->associationKey($server_url, $handle));
- return $association ? $association : null;
- }
-
-
-
- $serverKey = $this->associationServerKey($server_url);
-
-
- $serverAssociations = $this->connection->get($serverKey);
-
- if (!$serverAssociations) {
- return null;
- }
-
-
- $keys = array_keys($serverAssociations);
- sort($keys);
- $lastKey = $serverAssociations[array_pop($keys)];
-
-
- $association = $this->connection->get($lastKey);
- return $association ? $association : null;
- }
-
- function removeAssociation($server_url, $handle)
- {
-
-
- $serverKey = $this->associationServerKey($server_url);
- $associationKey = $this->associationKey($server_url,
- $handle);
-
-
- $serverAssociations = $this->connection->get($serverKey);
-
- if (!$serverAssociations) {
- return false;
- }
-
-
- $serverAssociations = array_flip($serverAssociations);
- if (!array_key_exists($associationKey, $serverAssociations)) {
- return false;
- }
-
-
- unset($serverAssociations[$associationKey]);
- $serverAssociations = array_flip($serverAssociations);
-
-
- $this->connection->set(
- $serverKey,
- $serverAssociations,
- $this->compress
- );
-
- return $this->connection->delete($associationKey);
- }
-
- function useNonce($server_url, $timestamp, $salt)
- {
- global $Auth_OpenID_SKEW;
-
-
- if (abs($timestamp - time()) > $Auth_OpenID_SKEW) {
- return false;
- }
-
-
-
- return $this->connection->add(
- 'openid_nonce_' . sha1($server_url) . '_' . sha1($salt),
- 1,
- $this->compress,
- $Auth_OpenID_SKEW);
- }
-
-
- function associationKey($server_url, $handle = null)
- {
- return 'openid_association_' . sha1($server_url) . '_' . sha1($handle);
- }
-
-
- function associationServerKey($server_url)
- {
- return 'openid_association_server_' . sha1($server_url);
- }
-
-
- function supportsCleanup()
- {
- return false;
- }
- }
|