MySQLStore.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * A MySQL store.
  4. *
  5. * @package OpenID
  6. */
  7. /**
  8. * Require the base class file.
  9. */
  10. require_once "Auth/OpenID/SQLStore.php";
  11. /**
  12. * An SQL store that uses MySQL as its backend.
  13. *
  14. * @package OpenID
  15. */
  16. class Auth_OpenID_MySQLStore extends Auth_OpenID_SQLStore {
  17. /**
  18. * @access private
  19. */
  20. function setSQL()
  21. {
  22. $this->sql['nonce_table'] =
  23. "CREATE TABLE %s (\n".
  24. " server_url VARCHAR(2047) NOT NULL,\n".
  25. " timestamp INTEGER NOT NULL,\n".
  26. " salt CHAR(40) NOT NULL,\n".
  27. " UNIQUE (server_url(255), timestamp, salt)\n".
  28. ") ENGINE=InnoDB";
  29. $this->sql['assoc_table'] =
  30. "CREATE TABLE %s (\n".
  31. " server_url VARCHAR(2047) NOT NULL,\n".
  32. " handle VARCHAR(255) NOT NULL,\n".
  33. " secret BLOB NOT NULL,\n".
  34. " issued INTEGER NOT NULL,\n".
  35. " lifetime INTEGER NOT NULL,\n".
  36. " assoc_type VARCHAR(64) NOT NULL,\n".
  37. " PRIMARY KEY (server_url(255), handle)\n".
  38. ") ENGINE=InnoDB";
  39. $this->sql['set_assoc'] =
  40. "REPLACE INTO %s (server_url, handle, secret, issued,\n".
  41. " lifetime, assoc_type) VALUES (?, ?, !, ?, ?, ?)";
  42. $this->sql['get_assocs'] =
  43. "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
  44. "WHERE server_url = ?";
  45. $this->sql['get_assoc'] =
  46. "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
  47. "WHERE server_url = ? AND handle = ?";
  48. $this->sql['remove_assoc'] =
  49. "DELETE FROM %s WHERE server_url = ? AND handle = ?";
  50. $this->sql['add_nonce'] =
  51. "INSERT INTO %s (server_url, timestamp, salt) VALUES (?, ?, ?)";
  52. $this->sql['clean_nonce'] =
  53. "DELETE FROM %s WHERE timestamp < ?";
  54. $this->sql['clean_assoc'] =
  55. "DELETE FROM %s WHERE issued + lifetime < ?";
  56. }
  57. /**
  58. * @access private
  59. */
  60. function blobEncode($blob)
  61. {
  62. return "0x" . bin2hex($blob);
  63. }
  64. }