test_auth.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_OpenId
  17. * @subpackage Demos
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. $dir = realpath(dirname(__FILE__)."/../../..");
  22. set_include_path("$dir/incubator/library" . PATH_SEPARATOR . "$dir/library" . PATH_SEPARATOR . get_include_path());
  23. /**
  24. * @see Zend_Auth
  25. */
  26. require_once "Zend/Auth.php";
  27. /**
  28. * @see Zend_Auth_Adapter_OpenId
  29. */
  30. require_once "Zend/Auth/Adapter/OpenId.php";
  31. $status = "";
  32. $auth = Zend_Auth::getInstance();
  33. if ((isset($_POST['openid_action']) &&
  34. $_POST['openid_action'] == "login" &&
  35. !empty($_POST['openid_identifier'])) ||
  36. isset($_GET['openid_mode']) ||
  37. isset($_POST['openid_mode'])) {
  38. $result = $auth->authenticate(
  39. new Zend_Auth_Adapter_OpenId(@$_POST['openid_identifier']));
  40. if ($result->isValid()) {
  41. Zend_OpenId::redirect(Zend_OpenId::selfURL());
  42. } else {
  43. $auth->clearIdentity();
  44. foreach ($result->getMessages() as $message) {
  45. $status .= "$message<br>\n";
  46. }
  47. }
  48. } else if ($auth->hasIdentity()) {
  49. if (isset($_POST['openid_action']) &&
  50. $_POST['openid_action'] == "logout") {
  51. $auth->clearIdentity();
  52. } else {
  53. $status = "You are logged-in as " . $auth->getIdentity() . "<br>\n";
  54. }
  55. }
  56. ?>
  57. <html><body>
  58. <?php echo "$status";?>
  59. <form method="post"><fieldset>
  60. <legend>OpenID Login</legend>
  61. <input type="text" name="openid_identifier" value="">
  62. <input type="submit" name="openid_action" value="login">
  63. <input type="submit" name="openid_action" value="logout">
  64. </fieldset></form></body></html>