common.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. require_once "lib/render.php";
  3. require_once "lib/session.php";
  4. require_once "lib/render/login.php";
  5. require_once "lib/render/about.php";
  6. require_once "lib/render/trust.php";
  7. require_once "Auth/OpenID/Server.php";
  8. require_once "Auth/OpenID/SReg.php";
  9. function authCancel($info)
  10. {
  11. if ($info) {
  12. setRequestInfo();
  13. $url = $info->getCancelURL();
  14. } else {
  15. $url = getServerURL();
  16. }
  17. return redirect_render($url);
  18. }
  19. function doAuth($info, $trusted=null, $fail_cancels=false,
  20. $idpSelect=null)
  21. {
  22. if (!$info) {
  23. // There is no authentication information, so bail
  24. return authCancel(null);
  25. }
  26. if ($info->idSelect()) {
  27. if ($idpSelect) {
  28. $req_url = idURL($idpSelect);
  29. } else {
  30. $trusted = false;
  31. }
  32. } else {
  33. $req_url = $info->identity;
  34. }
  35. $user = getLoggedInUser();
  36. setRequestInfo($info);
  37. if ((!$info->idSelect()) && ($req_url != idURL($user))) {
  38. return login_render(array(), $req_url, $req_url);
  39. }
  40. $trust_root = $info->trust_root;
  41. if ($trusted) {
  42. setRequestInfo();
  43. $server = getServer();
  44. $response = $info->answer(true, null, $req_url);
  45. // Answer with some sample Simple Registration data.
  46. $sreg_data = array(
  47. 'fullname' => 'Example User',
  48. 'nickname' => 'example',
  49. 'dob' => '1970-01-01',
  50. 'email' => 'invalid@example.com',
  51. 'gender' => 'F',
  52. 'postcode' => '12345',
  53. 'country' => 'ES',
  54. 'language' => 'eu',
  55. 'timezone' => 'America/New_York');
  56. // Add the simple registration response values to the OpenID
  57. // response message.
  58. $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest(
  59. $info);
  60. $sreg_response = Auth_OpenID_SRegResponse::extractResponse(
  61. $sreg_request, $sreg_data);
  62. $sreg_response->toMessage($response->fields);
  63. // Generate a response to send to the user agent.
  64. $webresponse = $server->encodeResponse($response);
  65. $new_headers = array();
  66. foreach ($webresponse->headers as $k => $v) {
  67. $new_headers[] = $k.": ".$v;
  68. }
  69. return array($new_headers, $webresponse->body);
  70. } elseif ($fail_cancels) {
  71. return authCancel($info);
  72. } else {
  73. return trust_render($info);
  74. }
  75. }
  76. ?>