/samples/myspaceid-openid-oauth-popup/common.php

https://github.com/paintitgold/myspace-php-sdk · PHP · 146 lines · 60 code · 21 blank · 65 comment · 3 complexity · 1baf84c6e9689b629382b3fa77a3b783 MD5 · raw file

  1. <?php
  2. define('LIB_PATH', "../../source/");
  3. define('CONFIG_PATH', "config/");
  4. define('LOCAL', true);
  5. $path_extra = dirname(dirname(dirname(__FILE__)));
  6. $path = ini_get('include_path');
  7. $path = CONFIG_PATH . PATH_SEPARATOR
  8. . LIB_PATH . PATH_SEPARATOR
  9. . $path_extra . PATH_SEPARATOR
  10. . $path;
  11. ini_set('include_path', $path);
  12. function displayError($message) {
  13. $error = $message;
  14. include 'index.php';
  15. exit(0);
  16. }
  17. function doIncludes() {
  18. /**
  19. * Require the OpenID consumer code.
  20. */
  21. require_once "Auth/OpenID/Consumer.php";
  22. /**
  23. * Require the "file store" module, which we'll need to store
  24. * OpenID information.
  25. */
  26. require_once "Auth/OpenID/FileStore.php";
  27. /**
  28. * Require the Simple Registration extension API.
  29. */
  30. require_once "Auth/OpenID/SReg.php";
  31. /**
  32. * Require the PAPE extension module.
  33. */
  34. require_once "Auth/OpenID/PAPE.php";
  35. /**
  36. * Require the OAuth extension module.
  37. */
  38. require_once "Auth/OpenID/OAuth.php";
  39. //loads the configuration file with you're consumer key and secret
  40. // uses the ternary operation for readability
  41. // http://en.wikipedia.org/wiki/Ternary_operation
  42. // BOOL ? (eval if BOOL == true) : (eval if BOOL == false);
  43. require_once LOCAL ? "config.MySpace.local.php" : "config.MySpace.php";
  44. }
  45. doIncludes();
  46. /**
  47. * &getStore() '&' returns by reference
  48. *
  49. * @return a new reference to Auth_OpenID_FileStore($store_path)
  50. */
  51. function &getStore() {
  52. /**
  53. * This is where the example will store its OpenID information.
  54. * You should change this path if you want the example store to be
  55. * created elsewhere. After you're done playing with the example
  56. * script, you'll have to remove this directory manually.
  57. */
  58. $store_path = TEMP_STORE_PATH;
  59. if (!file_exists($store_path) &&
  60. !mkdir($store_path)) {
  61. print "Could not create the FileStore directory '$store_path'. ".
  62. " Please check the effective permissions.";
  63. exit(0);
  64. }
  65. return new Auth_OpenID_FileStore($store_path);
  66. }
  67. /**
  68. * &getConsumer() '&' returns by reference
  69. *
  70. * @return reference to the $consumer object
  71. */
  72. function &getConsumer() {
  73. /**
  74. * Create a consumer object using the store object created
  75. * earlier.
  76. */
  77. $store = getStore();
  78. $consumer =& new Auth_OpenID_Consumer($store);
  79. return $consumer;
  80. }
  81. /**
  82. * Enter description here...
  83. *
  84. * @return HTTP or HTTPS
  85. */
  86. function getScheme() {
  87. $scheme = 'http';
  88. if (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') {
  89. $scheme .= 's';
  90. }
  91. return $scheme;
  92. }
  93. /**
  94. * Enter description here...
  95. *
  96. * @return URL to complete authentication
  97. */
  98. function getReturnTo() {
  99. return sprintf("%s://%s:%s%s/finish_auth.php",
  100. getScheme(), $_SERVER['SERVER_NAME'],
  101. $_SERVER['SERVER_PORT'],
  102. dirname($_SERVER['PHP_SELF']));
  103. }
  104. /**
  105. * Enter description here...
  106. *
  107. * @return URL that serves as the entry point for authenthication
  108. */
  109. function getTrustRoot() {
  110. //with full path including domain name, port and dir
  111. return sprintf("%s://%s:%s%s/",
  112. getScheme(), $_SERVER['SERVER_NAME'],
  113. $_SERVER['SERVER_PORT'],
  114. dirname($_SERVER['PHP_SELF']));
  115. }
  116. /*
  117. function getTrustRoot() {
  118. //with just the domain name and port
  119. return sprintf("%s://%s:%s/",
  120. getScheme(), $_SERVER['SERVER_NAME'],
  121. $_SERVER['SERVER_PORT']
  122. );
  123. }
  124. */
  125. ?>