PHP OpenID consumer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?PHP
  2. /* Poidsy 0.6 - http://chris.smith.name/projects/poidsy
  3. * Copyright (c) 2008-2010 Chris Smith
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. session_start();
  24. require('../../urlbuilder.inc.php');
  25. if (isset($_GET['cs'])) {
  26. unset($_SESSION['openid']);
  27. header('Location: ' . $_SERVER['SCRIPT_NAME']);
  28. exit;
  29. }
  30. $_SESSION['trustroot'] = URLBuilder::getCurrentURL();
  31. if (isset($_POST['openid_url']) || isset($_REQUEST['openid_mode'])) {
  32. // Proxy for non-JS users
  33. require('../../processor.php');
  34. } else {
  35. ?>
  36. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  37. "http://www.w3.org/TR/html4/strict.dtd">
  38. <html>
  39. <head>
  40. <title>OpenID consumer demonstration</title>
  41. <style type="text/css">
  42. input#openid_url {
  43. background: url('../../openid.gif') no-repeat; padding-left: 20px;
  44. }
  45. div { margin: 20px; padding: 5px; }
  46. </style>
  47. <script type="text/javascript">
  48. function tryJsLogin() {
  49. document.getElementById('target').src = 'iframe.php?openid.id=' + document.getElementById('openid_url').value;
  50. }
  51. function doSubmit() {
  52. //alert('Provider is requesting your interaction. Sending you away.');
  53. document.getElementById('form').submit();
  54. }
  55. function doError(msg) {
  56. document.getElementById('status').innerHTML = msg;
  57. document.getElementById('status').style.backgroundColor = "#a00";
  58. }
  59. function doSuccess(msg) {
  60. document.getElementById('status').innerHTML = msg;
  61. document.getElementById('status').style.backgroundColor = "#0a0";
  62. }
  63. </script>
  64. </head>
  65. <body>
  66. <h1>OpenID consumer demo</h1>
  67. <p>
  68. The login form below uses a hidden iframe to process the form
  69. (assuming the user has javascript enabled; if they don't, it falls back
  70. gracefully). If your identity provider implements checkid_immediate
  71. properly (which several don't appear to), and has enough information to
  72. authorise you without requiring your input, the entire login process
  73. should happen without any noticable change except for the status message.
  74. </p><p>
  75. If your identity provider requires interaction with you, the form
  76. will be submitted as usual and you'll leave this page (but, as usual, will
  77. return when your IdP is done with you). If your identity provider is
  78. <em>broken</em>, you won't see anything happening after the initial page
  79. load and redirect. This is either because the identity provider is trying to
  80. interact with you (via a hidden iframe) when it has been explicitly told
  81. not to, or because it is sending some kind of non-openID error response,
  82. such as a HTTP 500 error. This is the identity provider's fault (it's
  83. violating the OpenID specifications), not Poidsy's. If you were implementing
  84. this on a live site, you'd probably want to either add a timeout or monitor
  85. the iframe status to detect if it wasn't working and do a normal login.
  86. </p>
  87. <p>
  88. Note: if you are using Firefox and have the 'Disallow third party cookies'
  89. preference enabled, Firefox won't send cookies to your provider when it's
  90. loaded in the iframe. This almost certainly will mean that your provider
  91. can't validate your identity immediately, and thus you'll be redirected.
  92. Other browsers (such as IE and Safari) allow these cookies to be sent even
  93. if they disallow setting of third-party cookies.
  94. </p>
  95. <?PHP
  96. echo '<p>Time: ', date('r'), '. <a href="?cs">Clear session info</a></p>';
  97. if (isset($_SESSION['openid']['error'])) {
  98. echo '<div id="status" style="background-color: #a00;">An error occured: ', htmlentities($_SESSION['openid']['error']), '</div>';
  99. unset($_SESSION['openid']['error']);
  100. } else if (isset($_SESSION['openid']['validated']) && $_SESSION['openid']['validated']) {
  101. echo '<div id="status" style="background-color: #0a0;">Logged in as ', htmlentities($_SESSION['openid']['identity']), '</div>';
  102. } else {
  103. echo '<div id="status">Not logged in</div>';
  104. }
  105. ?>
  106. <form action="<?PHP echo htmlentities($_SERVER['REQUEST_URI']); ?>"
  107. method="post" onSubmit="tryJsLogin(); return false;" id="form">
  108. <input type="text" name="openid_url" id="openid_url">
  109. <input type="submit" value="Login">
  110. <iframe id="target" style="display: none;"></iframe>
  111. </form>
  112. </body>
  113. </html>
  114. <?PHP
  115. }
  116. ?>