Zend_Auth_Adapter_OpenId.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.auth.adapter.openid">
  4. <title>Open ID Authentication</title>
  5. <sect2 id="zend.auth.adapter.openid.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. The <classname>Zend_Auth_Adapter_OpenId</classname> adapter can be used to authenticate users using
  9. remote OpenID servers. This authentication method assumes that the user
  10. submits only their OpenID identity to the web application. They are
  11. then redirected to their OpenID provider to prove identity ownership
  12. using a password or some other method. This password is never provided to
  13. the web application.
  14. </para>
  15. <para>
  16. The OpenID identity is just a URI that points to a web site
  17. with information about a user, along with special tags that
  18. describes which server to use and which identity to submit there.
  19. You can read more about OpenID at the
  20. <ulink url="http://www.openid.net/">OpenID official site</ulink>.
  21. </para>
  22. <para>
  23. The <classname>Zend_Auth_Adapter_OpenId</classname> class wraps
  24. the <classname>Zend_OpenId_Consumer</classname> component, which implements the
  25. OpenID authentication protocol itself.
  26. </para>
  27. <note>
  28. <para>
  29. <classname>Zend_OpenId</classname> takes advantage of the <ulink url="http://php.net/gmp">GMP extension</ulink>,
  30. where available. Consider enabling the GMP extension for better performance when using
  31. <classname>Zend_Auth_Adapter_OpenId</classname>.
  32. </para>
  33. </note>
  34. </sect2>
  35. <sect2 id="zend.auth.adapter.openid.specifics">
  36. <title>Specifics</title>
  37. <para>
  38. As is the case for all <classname>Zend_Auth</classname> adapters, the <classname>Zend_Auth_Adapter_OpenId</classname>
  39. class implements <classname>Zend_Auth_Adapter_Interface</classname>, which
  40. defines one method: <code>authenticate()</code>. This method performs
  41. the authentication itself, but the object must be prepared prior to
  42. calling it. Such adapter preparation includes setting up the OpenID
  43. identity and some other <classname>Zend_OpenId</classname> specific options.
  44. </para>
  45. <para>
  46. However, as opposed to other <classname>Zend_Auth</classname> adapters, <classname>Zend_Auth_Adapter_OpenId</classname>
  47. performs authentication on an external server in two
  48. separate HTTP requests. So the <classname>Zend_Auth_Adapter_OpenId::authenticate()</classname> method
  49. must be called twice. On the first invocation the method won't return, but will
  50. redirect the user to their OpenID server. Then after the user is authenticated on the remote
  51. server, they will be redirected back and the script for this second
  52. request must call <classname>Zend_Auth_Adapter_OpenId::authenticate()</classname>
  53. again to verify the signature which comes with the redirected request from the
  54. server to complete the authentication process. On this second invocation, the
  55. method will return the <classname>Zend_Auth_Result</classname> object as expected.
  56. </para>
  57. <para>
  58. The following example shows the usage of <classname>Zend_Auth_Adapter_OpenId</classname>.
  59. As previously mentioned, the <classname>Zend_Auth_Adapter_OpenId::authenticate()</classname>
  60. must be called two times. The first time is after the user submits the HTML form with the
  61. <code>$_POST['openid_action']</code> set to <code>"login"</code>,
  62. and the second time is after the HTTP redirection from OpenID server with
  63. <code>$_GET['openid_mode']</code> or <code>$_POST['openid_mode']</code>
  64. set.
  65. </para>
  66. <programlisting role="php"><![CDATA[
  67. <?php
  68. $status = "";
  69. $auth = Zend_Auth::getInstance();
  70. if ((isset($_POST['openid_action']) &&
  71. $_POST['openid_action'] == "login" &&
  72. !empty($_POST['openid_identifier'])) ||
  73. isset($_GET['openid_mode']) ||
  74. isset($_POST['openid_mode'])) {
  75. $result = $auth->authenticate(
  76. new Zend_Auth_Adapter_OpenId(@$_POST['openid_identifier']));
  77. if ($result->isValid()) {
  78. $status = "You are logged in as "
  79. . $auth->getIdentity()
  80. . "<br>\n";
  81. } else {
  82. $auth->clearIdentity();
  83. foreach ($result->getMessages() as $message) {
  84. $status .= "$message<br>\n";
  85. }
  86. }
  87. } else if ($auth->hasIdentity()) {
  88. if (isset($_POST['openid_action']) &&
  89. $_POST['openid_action'] == "logout") {
  90. $auth->clearIdentity();
  91. } else {
  92. $status = "You are logged in as "
  93. . $auth->getIdentity()
  94. . "<br>\n";
  95. }
  96. }
  97. ?>
  98. <html><body>
  99. <?php echo htmlspecialchars($status);?>
  100. <form method="post"><fieldset>
  101. <legend>OpenID Login</legend>
  102. <input type="text" name="openid_identifier" value="">
  103. <input type="submit" name="openid_action" value="login">
  104. <input type="submit" name="openid_action" value="logout">
  105. </fieldset></form></body></html>
  106. */
  107. ]]></programlisting>
  108. <para>
  109. You may customize the OpenID authentication process in several way.
  110. You can, for example, receive the redirect from the OpenID server on a separate page,
  111. specifying the "root" of web site and using a custom
  112. <classname>Zend_OpenId_Consumer_Storage</classname> or a custom
  113. <classname>Zend_Controller_Response</classname>. You may also use
  114. the Simple Registration Extension to retrieve information about
  115. user from the OpenID server. All of these possibilities are described
  116. in more detail in the <classname>Zend_OpenId_Consumer</classname>
  117. chapter.
  118. </para>
  119. </sect2>
  120. </sect1>
  121. <!--
  122. vim:se ts=4 sw=4 et:
  123. -->