4 * This file specifies the interface for PHP OpenID store implementations.
8 * LICENSE: See the COPYING file included in this distribution.
11 * @author JanRain, Inc. <openid@janrain.com>
12 * @copyright 2005-2008 Janrain, Inc.
13 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
17 * This is the interface for the store objects the OpenID library
18 * uses. It is a single class that provides all of the persistence
19 * mechanisms that the OpenID library needs, for both servers and
20 * consumers. If you want to create an SQL-driven store, please see
21 * then {@link Auth_OpenID_SQLStore} class.
23 * Change: Version 2.0 removed the storeNonce, getAuthKey, and isDumb
24 * methods, and changed the behavior of the useNonce method to support
28 * @author JanRain, Inc. <openid@janrain.com>
30 class Auth_OpenID_OpenIDStore {
32 * This method puts an Association object into storage,
33 * retrievable by server URL and handle.
35 * @param string $server_url The URL of the identity server that
36 * this association is with. Because of the way the server portion
37 * of the library uses this interface, don't assume there are any
38 * limitations on the character set of the input string. In
39 * particular, expect to see unescaped non-url-safe characters in
40 * the server_url field.
42 * @param Association $association The Association to store.
44 function storeAssociation($server_url, $association)
46 trigger_error("Auth_OpenID_OpenIDStore::storeAssociation ".
47 "not implemented", E_USER_ERROR);
51 * Remove expired nonces from the store.
53 * Discards any nonce from storage that is old enough that its
54 * timestamp would not pass useNonce().
56 * This method is not called in the normal operation of the
57 * library. It provides a way for store admins to keep their
58 * storage from filling up with expired data.
60 * @return the number of nonces expired
62 function cleanupNonces()
64 trigger_error("Auth_OpenID_OpenIDStore::cleanupNonces ".
65 "not implemented", E_USER_ERROR);
69 * Remove expired associations from the store.
71 * This method is not called in the normal operation of the
72 * library. It provides a way for store admins to keep their
73 * storage from filling up with expired data.
75 * @return the number of associations expired.
77 function cleanupAssociations()
79 trigger_error("Auth_OpenID_OpenIDStore::cleanupAssociations ".
80 "not implemented", E_USER_ERROR);
84 * Shortcut for cleanupNonces(), cleanupAssociations().
86 * This method is not called in the normal operation of the
87 * library. It provides a way for store admins to keep their
88 * storage from filling up with expired data.
92 return array($this->cleanupNonces(),
93 $this->cleanupAssociations());
97 * Report whether this storage supports cleanup
99 function supportsCleanup()
105 * This method returns an Association object from storage that
106 * matches the server URL and, if specified, handle. It returns
107 * null if no such association is found or if the matching
108 * association is expired.
110 * If no handle is specified, the store may return any association
111 * which matches the server URL. If multiple associations are
112 * valid, the recommended return value for this method is the one
113 * most recently issued.
115 * This method is allowed (and encouraged) to garbage collect
116 * expired associations when found. This method must not return
117 * expired associations.
119 * @param string $server_url The URL of the identity server to get
120 * the association for. Because of the way the server portion of
121 * the library uses this interface, don't assume there are any
122 * limitations on the character set of the input string. In
123 * particular, expect to see unescaped non-url-safe characters in
124 * the server_url field.
126 * @param mixed $handle This optional parameter is the handle of
127 * the specific association to get. If no specific handle is
128 * provided, any valid association matching the server URL is
131 * @return Association The Association for the given identity
134 function getAssociation($server_url, $handle = null)
136 trigger_error("Auth_OpenID_OpenIDStore::getAssociation ".
137 "not implemented", E_USER_ERROR);
141 * This method removes the matching association if it's found, and
142 * returns whether the association was removed or not.
144 * @param string $server_url The URL of the identity server the
145 * association to remove belongs to. Because of the way the server
146 * portion of the library uses this interface, don't assume there
147 * are any limitations on the character set of the input
148 * string. In particular, expect to see unescaped non-url-safe
149 * characters in the server_url field.
151 * @param string $handle This is the handle of the association to
152 * remove. If there isn't an association found that matches both
153 * the given URL and handle, then there was no matching handle
156 * @return mixed Returns whether or not the given association existed.
158 function removeAssociation($server_url, $handle)
160 trigger_error("Auth_OpenID_OpenIDStore::removeAssociation ".
161 "not implemented", E_USER_ERROR);
165 * Called when using a nonce.
167 * This method should return C{True} if the nonce has not been
168 * used before, and store it for a while to make sure nobody
169 * tries to use the same value again. If the nonce has already
170 * been used, return C{False}.
172 * Change: In earlier versions, round-trip nonces were used and a
173 * nonce was only valid if it had been previously stored with
174 * storeNonce. Version 2.0 uses one-way nonces, requiring a
175 * different implementation here that does not depend on a
176 * storeNonce call. (storeNonce is no longer part of the
179 * @param string $nonce The nonce to use.
181 * @return bool Whether or not the nonce was valid.
183 function useNonce($server_url, $timestamp, $salt)
185 trigger_error("Auth_OpenID_OpenIDStore::useNonce ".
186 "not implemented", E_USER_ERROR);
190 * Removes all entries from the store; implementation is optional.