_Auth---OpenID---Consumer.php.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <!-- template designed by Marco Von Ballmoos -->
  6. <title>Docs for page Consumer.php</title>
  7. <link rel="stylesheet" href="../media/stylesheet.css" />
  8. <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
  9. </head>
  10. <body>
  11. <div class="page-body">
  12. <h2 class="file-name">/Auth/OpenID/Consumer.php</h2>
  13. <a name="sec-description"></a>
  14. <div class="info-box">
  15. <div class="info-box-title">Description</div>
  16. <div class="nav-bar">
  17. <span class="disabled">Description</span> |
  18. <a href="#sec-classes">Classes</a>
  19. | <a href="#sec-includes">Includes</a>
  20. | <a href="#sec-constants">Constants</a>
  21. | <a href="#sec-functions">Functions</a>
  22. </div>
  23. <div class="info-box-body">
  24. <!-- ========== Info from phpDoc block ========= -->
  25. <p class="short-description">This module documents the main interface with the OpenID consumer</p>
  26. <p class="description"><p>library. The only part of the library which has to be used and isn't documented in full here is the store required to create an Auth_OpenID_Consumer instance. More on the abstract store type and concrete implementations of it that are provided in the documentation for the Auth_OpenID_Consumer constructor.</p><p>OVERVIEW</p><p>The OpenID identity verification process most commonly uses the following steps, as visible to the user of this library:</p><p><ol><li>The user enters their OpenID into a field on the consumer's
  27. site, and hits a login button.</li><li>The consumer site discovers the user's OpenID server using the
  28. YADIS protocol.</li><li>The consumer site sends the browser a redirect to the identity
  29. server. This is the authentication request as described in
  30. the OpenID specification.</li><li>The identity server's site sends the browser a redirect back
  31. to the consumer site. This redirect contains the server's
  32. response to the authentication request.</li></ol> The most important part of the flow to note is the consumer's site must handle two separate HTTP requests in order to perform the full identity check.</p><p>LIBRARY DESIGN</p><p>This consumer library is designed with that flow in mind. The goal is to make it as easy as possible to perform the above steps securely.</p><p>At a high level, there are two important parts in the consumer library. The first important part is this module, which contains the interface to actually use this library. The second is the Auth_OpenID_Interface class, which describes the interface to use if you need to create a custom method for storing the state this library needs to maintain between requests.</p><p>In general, the second part is less important for users of the library to know about, as several implementations are provided which cover a wide variety of situations in which consumers may use the library.</p><p>This module contains a class, Auth_OpenID_Consumer, with methods corresponding to the actions necessary in each of steps 2, 3, and 4 described in the overview. Use of this library should be as easy as creating an Auth_OpenID_Consumer instance and calling the methods appropriate for the action the site wants to take.</p><p>STORES AND DUMB MODE</p><p>OpenID is a protocol that works best when the consumer site is able to store some state. This is the normal mode of operation for the protocol, and is sometimes referred to as smart mode. There is also a fallback mode, known as dumb mode, which is available when the consumer site is not able to store state. This mode should be avoided when possible, as it leaves the implementation more vulnerable to replay attacks.</p><p>The mode the library works in for normal operation is determined by the store that it is given. The store is an abstraction that handles the data that the consumer needs to manage between http requests in order to operate efficiently and securely.</p><p>Several store implementation are provided, and the interface is fully documented so that custom stores can be used as well. See the documentation for the Auth_OpenID_Consumer class for more information on the interface for stores. The implementations that are provided allow the consumer site to store the necessary data in several different ways, including several SQL databases and normal files on disk.</p><p>There is an additional concrete store provided that puts the system in dumb mode. This is not recommended, as it removes the library's ability to stop replay attacks reliably. It still uses time-based checking to make replay attacks only possible within a small window, but they remain possible within that window. This store should only be used if the consumer site has no way to retain data between requests at all.</p><p>IMMEDIATE MODE</p><p>In the flow described above, the user may need to confirm to the lidentity server that it's ok to authorize his or her identity. The server may draw pages asking for information from the user before it redirects the browser back to the consumer's site. This is generally transparent to the consumer site, so it is typically ignored as an implementation detail.</p><p>There can be times, however, where the consumer site wants to get a response immediately. When this is the case, the consumer can put the library in immediate mode. In immediate mode, there is an extra response possible from the server, which is essentially the server reporting that it doesn't have enough information to answer the question yet.</p><p>USING THIS LIBRARY</p><p>Integrating this library into an application is usually a relatively straightforward process. The process should basically follow this plan:</p><p>Add an OpenID login field somewhere on your site. When an OpenID is entered in that field and the form is submitted, it should make a request to the your site which includes that OpenID URL.</p><p>First, the application should instantiate the Auth_OpenID_Consumer class using the store of choice (Auth_OpenID_FileStore or one of the SQL-based stores). If the application has a custom session-management implementation, an object implementing the <a href="../OpenID/Auth_Yadis_PHPSession.html">Auth_Yadis_PHPSession</a> interface should be passed as the second parameter. Otherwise, the default uses $_SESSION.</p><p>Next, the application should call the Auth_OpenID_Consumer object's 'begin' method. This method takes the OpenID URL. The 'begin' method returns an Auth_OpenID_AuthRequest object.</p><p>Next, the application should call the 'redirectURL' method of the Auth_OpenID_AuthRequest object. The 'return_to' URL parameter is the URL that the OpenID server will send the user back to after attempting to verify his or her identity. The 'trust_root' is the URL (or URL pattern) that identifies your web site to the user when he or she is authorizing it. Send a redirect to the resulting URL to the user's browser.</p><p>That's the first half of the authentication process. The second half of the process is done after the user's ID server sends the user's browser a redirect back to your site to complete their login.</p><p>When that happens, the user will contact your site at the URL given as the 'return_to' URL to the Auth_OpenID_AuthRequest::redirectURL call made above. The request will have several query parameters added to the URL by the identity server as the information necessary to finish the request.</p><p>Lastly, instantiate an Auth_OpenID_Consumer instance as above and call its 'complete' method, passing in all the received query arguments.</p><p>There are multiple possible return types possible from that method. These indicate the whether or not the login was successful, and include any additional information appropriate for their type.</p><p>PHP versions 4 and 5</p><p>LICENSE: See the COPYING file included in this distribution.</p></p>
  33. <ul class="tags">
  34. <li><span class="field">author:</span> JanRain, Inc. &lt;<a href="mailto:openid@janrain.com">openid@janrain.com</a>&gt;</li>
  35. <li><span class="field">copyright:</span> 2005-2008 Janrain, Inc.</li>
  36. <li><span class="field">license:</span> <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache</a></li>
  37. </ul>
  38. </div>
  39. </div>
  40. <a name="sec-classes"></a>
  41. <div class="info-box">
  42. <div class="info-box-title">Classes</div>
  43. <div class="nav-bar">
  44. <a href="#sec-description">Description</a> |
  45. <span class="disabled">Classes</span>
  46. | <a href="#sec-includes">Includes</a>
  47. | <a href="#sec-constants">Constants</a>
  48. | <a href="#sec-functions">Functions</a>
  49. </div>
  50. <div class="info-box-body">
  51. <table cellpadding="2" cellspacing="0" class="class-table">
  52. <tr>
  53. <th class="class-table-header">Class</th>
  54. <th class="class-table-header">Description</th>
  55. </tr>
  56. <tr>
  57. <td style="padding-right: 2em; vertical-align: top">
  58. <a href="../OpenID/Auth_OpenID_Consumer.html">Auth_OpenID_Consumer</a>
  59. </td>
  60. <td>
  61. An OpenID consumer implementation that performs discovery and does session management. See the Consumer.php file documentation for more information.
  62. </td>
  63. </tr>
  64. <tr>
  65. <td style="padding-right: 2em; vertical-align: top">
  66. <a href="../OpenID/Auth_OpenID_DiffieHellmanSHA1ConsumerSession.html">Auth_OpenID_DiffieHellmanSHA1ConsumerSession</a>
  67. </td>
  68. <td>
  69. A class implementing HMAC/DH-SHA1 consumer sessions.
  70. </td>
  71. </tr>
  72. <tr>
  73. <td style="padding-right: 2em; vertical-align: top">
  74. <a href="../OpenID/Auth_OpenID_DiffieHellmanSHA256ConsumerSession.html">Auth_OpenID_DiffieHellmanSHA256ConsumerSession</a>
  75. </td>
  76. <td>
  77. A class implementing HMAC/DH-SHA256 consumer sessions.
  78. </td>
  79. </tr>
  80. <tr>
  81. <td style="padding-right: 2em; vertical-align: top">
  82. <a href="../OpenID/Auth_OpenID_PlainTextConsumerSession.html">Auth_OpenID_PlainTextConsumerSession</a>
  83. </td>
  84. <td>
  85. A class implementing plaintext consumer sessions.
  86. </td>
  87. </tr>
  88. <tr>
  89. <td style="padding-right: 2em; vertical-align: top">
  90. <a href="../OpenID/Auth_OpenID_GenericConsumer.html">Auth_OpenID_GenericConsumer</a>
  91. </td>
  92. <td>
  93. This class is the interface to the OpenID consumer logic.
  94. </td>
  95. </tr>
  96. <tr>
  97. <td style="padding-right: 2em; vertical-align: top">
  98. <a href="../OpenID/Auth_OpenID_AuthRequest.html">Auth_OpenID_AuthRequest</a>
  99. </td>
  100. <td>
  101. This class represents an authentication request from a consumer to an OpenID server.
  102. </td>
  103. </tr>
  104. <tr>
  105. <td style="padding-right: 2em; vertical-align: top">
  106. <a href="../OpenID/Auth_OpenID_ConsumerResponse.html">Auth_OpenID_ConsumerResponse</a>
  107. </td>
  108. <td>
  109. The base class for responses from the Auth_OpenID_Consumer.
  110. </td>
  111. </tr>
  112. <tr>
  113. <td style="padding-right: 2em; vertical-align: top">
  114. <a href="../OpenID/Auth_OpenID_SuccessResponse.html">Auth_OpenID_SuccessResponse</a>
  115. </td>
  116. <td>
  117. A response with a status of Auth_OpenID_SUCCESS. Indicates that
  118. </td>
  119. </tr>
  120. <tr>
  121. <td style="padding-right: 2em; vertical-align: top">
  122. <a href="../OpenID/Auth_OpenID_FailureResponse.html">Auth_OpenID_FailureResponse</a>
  123. </td>
  124. <td>
  125. A response with a status of Auth_OpenID_FAILURE. Indicates that the OpenID protocol has failed. This could be locally or remotely triggered. This has three relevant attributes:
  126. </td>
  127. </tr>
  128. <tr>
  129. <td style="padding-right: 2em; vertical-align: top">
  130. <a href="../OpenID/Auth_OpenID_TypeURIMismatch.html">Auth_OpenID_TypeURIMismatch</a>
  131. </td>
  132. <td>
  133. A specific, internal failure used to detect type URI mismatch.
  134. </td>
  135. </tr>
  136. <tr>
  137. <td style="padding-right: 2em; vertical-align: top">
  138. <a href="../OpenID/Auth_OpenID_ServerErrorContainer.html">Auth_OpenID_ServerErrorContainer</a>
  139. </td>
  140. <td>
  141. Exception that is raised when the server returns a 400 response code to a direct request.
  142. </td>
  143. </tr>
  144. <tr>
  145. <td style="padding-right: 2em; vertical-align: top">
  146. <a href="../OpenID/Auth_OpenID_CancelResponse.html">Auth_OpenID_CancelResponse</a>
  147. </td>
  148. <td>
  149. A response with a status of Auth_OpenID_CANCEL. Indicates that the user cancelled the OpenID authentication request. This has two relevant attributes:
  150. </td>
  151. </tr>
  152. <tr>
  153. <td style="padding-right: 2em; vertical-align: top">
  154. <a href="../OpenID/Auth_OpenID_SetupNeededResponse.html">Auth_OpenID_SetupNeededResponse</a>
  155. </td>
  156. <td>
  157. A response with a status of Auth_OpenID_SETUP_NEEDED. Indicates that the request was in immediate mode, and the server is unable to authenticate the user without further interaction.
  158. </td>
  159. </tr>
  160. </table>
  161. </div>
  162. </div>
  163. <a name="sec-includes"></a>
  164. <div class="info-box">
  165. <div class="info-box-title">Includes</div>
  166. <div class="nav-bar">
  167. <a href="#sec-description">Description</a> |
  168. <a href="#sec-classes">Classes</a>
  169. | <span class="disabled">Includes</span>
  170. | <a href="#sec-constants">Constants</a>
  171. | <a href="#sec-functions">Functions</a>
  172. </div>
  173. <div class="info-box-body">
  174. <a name="_Auth/OpenID/DiffieHellman_php"><!-- --></a>
  175. <div class="evenrow">
  176. <div>
  177. <span class="include-title">
  178. <span class="include-type">require_once</span>
  179. (<span class="include-name">"Auth/OpenID/DiffieHellman.php"</span>)
  180. (line <span class="line-number">168</span>)
  181. </span>
  182. </div>
  183. <!-- ========== Info from phpDoc block ========= -->
  184. </div>
  185. <a name="_Auth/OpenID/CryptUtil_php"><!-- --></a>
  186. <div class="oddrow">
  187. <div>
  188. <span class="include-title">
  189. <span class="include-type">require_once</span>
  190. (<span class="include-name">"Auth/OpenID/CryptUtil.php"</span>)
  191. (line <span class="line-number">167</span>)
  192. </span>
  193. </div>
  194. <!-- ========== Info from phpDoc block ========= -->
  195. </div>
  196. <a name="_Auth/OpenID/Nonce_php"><!-- --></a>
  197. <div class="evenrow">
  198. <div>
  199. <span class="include-title">
  200. <span class="include-type">require_once</span>
  201. (<span class="include-name"><a href="../OpenID/_Auth---OpenID---Nonce.php.html">"Auth/OpenID/Nonce.php"</a></span>)
  202. (line <span class="line-number">170</span>)
  203. </span>
  204. </div>
  205. <!-- ========== Info from phpDoc block ========= -->
  206. </div>
  207. <a name="_Auth/OpenID/Message_php"><!-- --></a>
  208. <div class="oddrow">
  209. <div>
  210. <span class="include-title">
  211. <span class="include-type">require_once</span>
  212. (<span class="include-name"><a href="../OpenID/_Auth---OpenID---Message.php.html">"Auth/OpenID/Message.php"</a></span>)
  213. (line <span class="line-number">164</span>)
  214. </span>
  215. </div>
  216. <!-- ========== Info from phpDoc block ========= -->
  217. </div>
  218. <a name="_Auth/OpenID/KVForm_php"><!-- --></a>
  219. <div class="evenrow">
  220. <div>
  221. <span class="include-title">
  222. <span class="include-type">require_once</span>
  223. (<span class="include-name">"Auth/OpenID/KVForm.php"</span>)
  224. (line <span class="line-number">169</span>)
  225. </span>
  226. </div>
  227. <!-- ========== Info from phpDoc block ========= -->
  228. </div>
  229. <a name="_Auth/OpenID_php"><!-- --></a>
  230. <div class="oddrow">
  231. <div>
  232. <span class="include-title">
  233. <span class="include-type">require_once</span>
  234. (<span class="include-name"><a href="../OpenID/_Auth---OpenID.php.html">"Auth/OpenID.php"</a></span>)
  235. (line <span class="line-number">163</span>)
  236. </span>
  237. </div>
  238. <!-- ========== Info from phpDoc block ========= -->
  239. <p class="short-description">Require utility classes and functions for the consumer.</p>
  240. </div>
  241. <a name="_Auth/Yadis/XRI_php"><!-- --></a>
  242. <div class="evenrow">
  243. <div>
  244. <span class="include-title">
  245. <span class="include-type">require_once</span>
  246. (<span class="include-name">"Auth/Yadis/XRI.php"</span>)
  247. (line <span class="line-number">174</span>)
  248. </span>
  249. </div>
  250. <!-- ========== Info from phpDoc block ========= -->
  251. </div>
  252. <a name="_Auth/Yadis/Manager_php"><!-- --></a>
  253. <div class="oddrow">
  254. <div>
  255. <span class="include-title">
  256. <span class="include-type">require_once</span>
  257. (<span class="include-name"><a href="../OpenID/_Auth---Yadis---Manager.php.html">"Auth/Yadis/Manager.php"</a></span>)
  258. (line <span class="line-number">173</span>)
  259. </span>
  260. </div>
  261. <!-- ========== Info from phpDoc block ========= -->
  262. </div>
  263. <a name="_Auth/OpenID/URINorm_php"><!-- --></a>
  264. <div class="evenrow">
  265. <div>
  266. <span class="include-title">
  267. <span class="include-type">require_once</span>
  268. (<span class="include-name">"Auth/OpenID/URINorm.php"</span>)
  269. (line <span class="line-number">172</span>)
  270. </span>
  271. </div>
  272. <!-- ========== Info from phpDoc block ========= -->
  273. </div>
  274. <a name="_Auth/OpenID/Discover_php"><!-- --></a>
  275. <div class="oddrow">
  276. <div>
  277. <span class="include-title">
  278. <span class="include-type">require_once</span>
  279. (<span class="include-name">"Auth/OpenID/Discover.php"</span>)
  280. (line <span class="line-number">171</span>)
  281. </span>
  282. </div>
  283. <!-- ========== Info from phpDoc block ========= -->
  284. </div>
  285. <a name="_Auth/OpenID/Association_php"><!-- --></a>
  286. <div class="evenrow">
  287. <div>
  288. <span class="include-title">
  289. <span class="include-type">require_once</span>
  290. (<span class="include-name"><a href="../OpenID/_Auth---OpenID---Association.php.html">"Auth/OpenID/Association.php"</a></span>)
  291. (line <span class="line-number">166</span>)
  292. </span>
  293. </div>
  294. <!-- ========== Info from phpDoc block ========= -->
  295. </div>
  296. <a name="_Auth/OpenID/HMAC_php"><!-- --></a>
  297. <div class="oddrow">
  298. <div>
  299. <span class="include-title">
  300. <span class="include-type">require_once</span>
  301. (<span class="include-name">"Auth/OpenID/HMAC.php"</span>)
  302. (line <span class="line-number">165</span>)
  303. </span>
  304. </div>
  305. <!-- ========== Info from phpDoc block ========= -->
  306. </div>
  307. </div>
  308. </div>
  309. <a name="sec-constants"></a>
  310. <div class="info-box">
  311. <div class="info-box-title">Constants</div>
  312. <div class="nav-bar">
  313. <a href="#sec-description">Description</a> |
  314. <a href="#sec-classes">Classes</a>
  315. | <a href="#sec-includes">Includes</a>
  316. | <span class="disabled">Constants</span>
  317. | <a href="#sec-functions">Functions</a>
  318. </div>
  319. <div class="info-box-body">
  320. <a name="defineAuth_OpenID_CANCEL"><!-- --></a>
  321. <div class="evenrow">
  322. <div>
  323. <span class="const-title">
  324. <span class="const-name">Auth_OpenID_CANCEL</span> = 'cancel'
  325. (line <span class="line-number">185</span>)
  326. </span>
  327. </div>
  328. <!-- ========== Info from phpDoc block ========= -->
  329. <p class="short-description">Status to indicate cancellation of OpenID authentication.</p>
  330. </div>
  331. <a name="defineAuth_OpenID_FAILURE"><!-- --></a>
  332. <div class="oddrow">
  333. <div>
  334. <span class="const-title">
  335. <span class="const-name">Auth_OpenID_FAILURE</span> = 'failure'
  336. (line <span class="line-number">191</span>)
  337. </span>
  338. </div>
  339. <!-- ========== Info from phpDoc block ========= -->
  340. <p class="short-description">This is the status code completeAuth returns when the value it received indicated an invalid login.</p>
  341. </div>
  342. <a name="defineAuth_OpenID_PARSE_ERROR"><!-- --></a>
  343. <div class="evenrow">
  344. <div>
  345. <span class="const-title">
  346. <span class="const-name">Auth_OpenID_PARSE_ERROR</span> = 'parse error'
  347. (line <span class="line-number">206</span>)
  348. </span>
  349. </div>
  350. <!-- ========== Info from phpDoc block ========= -->
  351. <p class="short-description">This is the status code beginAuth returns when the page fetched from the entered OpenID URL doesn't contain the necessary link tags to function as an identity page.</p>
  352. </div>
  353. <a name="defineAuth_OpenID_SETUP_NEEDED"><!-- --></a>
  354. <div class="oddrow">
  355. <div>
  356. <span class="const-title">
  357. <span class="const-name">Auth_OpenID_SETUP_NEEDED</span> = 'setup needed'
  358. (line <span class="line-number">199</span>)
  359. </span>
  360. </div>
  361. <!-- ========== Info from phpDoc block ========= -->
  362. <p class="short-description">This is the status code completeAuth returns when the <a href="../OpenID/Auth_OpenID_Consumer.html">Auth_OpenID_Consumer</a> instance is in immediate mode, and the identity server sends back a URL to send the user to to complete his or her login.</p>
  363. </div>
  364. <a name="defineAuth_OpenID_SUCCESS"><!-- --></a>
  365. <div class="evenrow">
  366. <div>
  367. <span class="const-title">
  368. <span class="const-name">Auth_OpenID_SUCCESS</span> = 'success'
  369. (line <span class="line-number">180</span>)
  370. </span>
  371. </div>
  372. <!-- ========== Info from phpDoc block ========= -->
  373. <p class="short-description">This is the status code returned when the complete method returns successfully.</p>
  374. </div>
  375. </div>
  376. </div>
  377. <a name="sec-functions"></a>
  378. <div class="info-box">
  379. <div class="info-box-title">Functions</div>
  380. <div class="nav-bar">
  381. <a href="#sec-description">Description</a> |
  382. <a href="#sec-classes">Classes</a>
  383. | <a href="#sec-includes">Includes</a>
  384. | <a href="#sec-constants">Constants</a>
  385. | <span class="disabled">Functions</span>
  386. </div>
  387. <div class="info-box-body">
  388. <a name="functionAuth_OpenID_getAvailableSessionTypes" id="functionAuth_OpenID_getAvailableSessionTypes"><!-- --></a>
  389. <div class="oddrow">
  390. <div>
  391. <span class="method-title">Auth_OpenID_getAvailableSessionTypes</span> (line <span class="line-number">551</span>)
  392. </div>
  393. <!-- ========== Info from phpDoc block ========= -->
  394. <p class="short-description">Returns available session types.</p>
  395. <div class="method-signature">
  396. <span class="method-result">void</span>
  397. <span class="method-name">
  398. Auth_OpenID_getAvailableSessionTypes
  399. </span>
  400. ()
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. <p class="notes" id="credit">
  406. Documentation generated on Tue, 21 Apr 2009 11:31:30 -0700 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.3.2</a>
  407. </p>
  408. </div></body>
  409. </html>