finish_auth.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. require_once "common.php";
  3. session_start();
  4. function escape($thing) {
  5. return htmlentities($thing);
  6. }
  7. function run() {
  8. $consumer = getConsumer();
  9. // Complete the authentication process using the server's
  10. // response.
  11. $return_to = getReturnTo();
  12. $response = $consumer->complete($return_to);
  13. // Check the response status.
  14. if ($response->status == Auth_OpenID_CANCEL) {
  15. // This means the authentication was cancelled.
  16. $msg = 'Verification cancelled.';
  17. } else if ($response->status == Auth_OpenID_FAILURE) {
  18. // Authentication failed; display the error message.
  19. $msg = "OpenID authentication failed: " . $response->message;
  20. } else if ($response->status == Auth_OpenID_SUCCESS) {
  21. // This means the authentication succeeded; extract the
  22. // identity URL and Simple Registration data (if it was
  23. // returned).
  24. $openid = $response->getDisplayIdentifier();
  25. $esc_identity = escape($openid);
  26. $success = sprintf('You have successfully verified ' .
  27. '<a href="%s">%s</a> as your identity.',
  28. $esc_identity, $esc_identity);
  29. if ($response->endpoint->canonicalID) {
  30. $escaped_canonicalID = escape($response->endpoint->canonicalID);
  31. $success .= ' (XRI CanonicalID: '.$escaped_canonicalID.') ';
  32. }
  33. $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
  34. $sreg = $sreg_resp->contents();
  35. if (@$sreg['email']) {
  36. $success .= " You also returned '".escape($sreg['email']).
  37. "' as your email.";
  38. }
  39. if (@$sreg['nickname']) {
  40. $success .= " Your nickname is '".escape($sreg['nickname']).
  41. "'.";
  42. }
  43. if (@$sreg['fullname']) {
  44. $success .= " Your fullname is '".escape($sreg['fullname']).
  45. "'.";
  46. }
  47. $pape_resp = Auth_OpenID_PAPE_Response::fromSuccessResponse($response);
  48. if ($pape_resp) {
  49. if ($pape_resp->auth_policies) {
  50. $success .= "<p>The following PAPE policies affected the authentication:</p><ul>";
  51. foreach ($pape_resp->auth_policies as $uri) {
  52. $escaped_uri = escape($uri);
  53. $success .= "<li><tt>$escaped_uri</tt></li>";
  54. }
  55. $success .= "</ul>";
  56. } else {
  57. $success .= "<p>No PAPE policies affected the authentication.</p>";
  58. }
  59. if ($pape_resp->auth_age) {
  60. $age = escape($pape_resp->auth_age);
  61. $success .= "<p>The authentication age returned by the " .
  62. "server is: <tt>".$age."</tt></p>";
  63. }
  64. if ($pape_resp->nist_auth_level) {
  65. $auth_level = escape($pape_resp->nist_auth_level);
  66. $success .= "<p>The NIST auth level returned by the " .
  67. "server is: <tt>".$auth_level."</tt></p>";
  68. }
  69. } else {
  70. $success .= "<p>No PAPE response was sent by the provider.</p>";
  71. }
  72. }
  73. include 'index.php';
  74. }
  75. run();
  76. ?>