PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Auth/OpenID/Interface.php

http://github.com/openid/php-openid
PHP | 194 lines | 43 code | 10 blank | 141 comment | 0 complexity | f1426160b4a656802434e01ad9fce27f MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * This file specifies the interface for PHP OpenID store implementations.
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * LICENSE: See the COPYING file included in this distribution.
  8. *
  9. * @package OpenID
  10. * @author JanRain, Inc. <openid@janrain.com>
  11. * @copyright 2005-2008 Janrain, Inc.
  12. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
  13. */
  14. /**
  15. * This is the interface for the store objects the OpenID library
  16. * uses. It is a single class that provides all of the persistence
  17. * mechanisms that the OpenID library needs, for both servers and
  18. * consumers. If you want to create an SQL-driven store, please see
  19. * then {@link Auth_OpenID_SQLStore} class.
  20. *
  21. * Change: Version 2.0 removed the storeNonce, getAuthKey, and isDumb
  22. * methods, and changed the behavior of the useNonce method to support
  23. * one-way nonces.
  24. *
  25. * @package OpenID
  26. * @author JanRain, Inc. <openid@janrain.com>
  27. */
  28. class Auth_OpenID_OpenIDStore {
  29. /**
  30. * This method puts an Association object into storage,
  31. * retrievable by server URL and handle.
  32. *
  33. * @param string $server_url The URL of the identity server that
  34. * this association is with. Because of the way the server portion
  35. * of the library uses this interface, don't assume there are any
  36. * limitations on the character set of the input string. In
  37. * particular, expect to see unescaped non-url-safe characters in
  38. * the server_url field.
  39. *
  40. * @param Auth_OpenID_Association $association The Association to store.
  41. */
  42. function storeAssociation($server_url, $association)
  43. {
  44. trigger_error("Auth_OpenID_OpenIDStore::storeAssociation not implemented", E_USER_ERROR);
  45. }
  46. /**
  47. * Remove expired nonces from the store.
  48. *
  49. * Discards any nonce from storage that is old enough that its
  50. * timestamp would not pass useNonce().
  51. *
  52. * This method is not called in the normal operation of the
  53. * library. It provides a way for store admins to keep their
  54. * storage from filling up with expired data.
  55. *
  56. * @return int the number of nonces expired
  57. */
  58. function cleanupNonces()
  59. {
  60. trigger_error("Auth_OpenID_OpenIDStore::cleanupNonces not implemented", E_USER_ERROR);
  61. return 0;
  62. }
  63. /**
  64. * Remove expired associations from the store.
  65. *
  66. * This method is not called in the normal operation of the
  67. * library. It provides a way for store admins to keep their
  68. * storage from filling up with expired data.
  69. *
  70. * @return int the number of associations expired.
  71. */
  72. function cleanupAssociations()
  73. {
  74. trigger_error("Auth_OpenID_OpenIDStore::cleanupAssociations not implemented", E_USER_ERROR);
  75. return 0;
  76. }
  77. /**
  78. * Shortcut for cleanupNonces(), cleanupAssociations().
  79. *
  80. * This method is not called in the normal operation of the
  81. * library. It provides a way for store admins to keep their
  82. * storage from filling up with expired data.
  83. * @return array
  84. */
  85. function cleanup()
  86. {
  87. return [$this->cleanupNonces(), $this->cleanupAssociations()];
  88. }
  89. /**
  90. * Report whether this storage supports cleanup
  91. */
  92. function supportsCleanup()
  93. {
  94. return true;
  95. }
  96. /**
  97. * This method returns an Association object from storage that
  98. * matches the server URL and, if specified, handle. It returns
  99. * null if no such association is found or if the matching
  100. * association is expired.
  101. *
  102. * If no handle is specified, the store may return any association
  103. * which matches the server URL. If multiple associations are
  104. * valid, the recommended return value for this method is the one
  105. * most recently issued.
  106. *
  107. * This method is allowed (and encouraged) to garbage collect
  108. * expired associations when found. This method must not return
  109. * expired associations.
  110. *
  111. * @param string $server_url The URL of the identity server to get
  112. * the association for. Because of the way the server portion of
  113. * the library uses this interface, don't assume there are any
  114. * limitations on the character set of the input string. In
  115. * particular, expect to see unescaped non-url-safe characters in
  116. * the server_url field.
  117. *
  118. * @param mixed $handle This optional parameter is the handle of
  119. * the specific association to get. If no specific handle is
  120. * provided, any valid association matching the server URL is
  121. * returned.
  122. *
  123. * @return Auth_OpenID_Association The Association for the given identity server.
  124. */
  125. function getAssociation($server_url, $handle = null)
  126. {
  127. trigger_error("Auth_OpenID_OpenIDStore::getAssociation not implemented", E_USER_ERROR);
  128. return null;
  129. }
  130. /**
  131. * This method removes the matching association if it's found, and
  132. * returns whether the association was removed or not.
  133. *
  134. * @param string $server_url The URL of the identity server the
  135. * association to remove belongs to. Because of the way the server
  136. * portion of the library uses this interface, don't assume there
  137. * are any limitations on the character set of the input
  138. * string. In particular, expect to see unescaped non-url-safe
  139. * characters in the server_url field.
  140. *
  141. * @param string $handle This is the handle of the association to
  142. * remove. If there isn't an association found that matches both
  143. * the given URL and handle, then there was no matching handle
  144. * found.
  145. *
  146. * @return mixed Returns whether or not the given association existed.
  147. */
  148. function removeAssociation($server_url, $handle)
  149. {
  150. trigger_error("Auth_OpenID_OpenIDStore::removeAssociation not implemented", E_USER_ERROR);
  151. return null;
  152. }
  153. /**
  154. * Called when using a nonce.
  155. *
  156. * This method should return C{True} if the nonce has not been
  157. * used before, and store it for a while to make sure nobody
  158. * tries to use the same value again. If the nonce has already
  159. * been used, return C{False}.
  160. *
  161. * Change: In earlier versions, round-trip nonces were used and a
  162. * nonce was only valid if it had been previously stored with
  163. * storeNonce. Version 2.0 uses one-way nonces, requiring a
  164. * different implementation here that does not depend on a
  165. * storeNonce call. (storeNonce is no longer part of the
  166. * interface.
  167. *
  168. * @param string $server_url
  169. * @param int $timestamp
  170. * @param string $salt
  171. * @return bool Whether or not the nonce was valid.
  172. */
  173. function useNonce($server_url, $timestamp, $salt)
  174. {
  175. trigger_error("Auth_OpenID_OpenIDStore::useNonce not implemented", E_USER_ERROR);
  176. return false;
  177. }
  178. /**
  179. * Removes all entries from the store; implementation is optional.
  180. */
  181. function reset()
  182. {
  183. }
  184. }