OAuth_TestServer.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php //vim: foldmethod=marker
  2. //require_once("OAuth.php");
  3. class TestOAuthServer extends OAuthServer {
  4. public function get_signature_methods() {
  5. return $this->signature_methods;
  6. }
  7. }
  8. class TestOAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod_RSA_SHA1 {
  9. public function fetch_private_cert(&$request) {
  10. $cert = <<<EOD
  11. -----BEGIN PRIVATE KEY-----
  12. MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
  13. A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d
  14. 7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ
  15. hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H
  16. X9u2AC2ry8vD/l7cqedtwMPp9k7TubgNFo+NGvKsl2ynyprOZR1xjQ7WgrgVB+mm
  17. uScOM/5HVceFuGRDhYTCObE+y1kxRloNYXnx3ei1zbeYLPCHdhxRYW7T0qcynNmw
  18. rn05/KO2RLjgQNalsQJBANeA3Q4Nugqy4QBUCEC09SqylT2K9FrrItqL2QKc9v0Z
  19. zO2uwllCbg0dwpVuYPYXYvikNHHg+aCWF+VXsb9rpPsCQQDWR9TT4ORdzoj+Nccn
  20. qkMsDmzt0EfNaAOwHOmVJ2RVBspPcxt5iN4HI7HNeG6U5YsFBb+/GZbgfBT3kpNG
  21. WPTpAkBI+gFhjfJvRw38n3g/+UeAkwMI2TJQS4n8+hid0uus3/zOjDySH3XHCUno
  22. cn1xOJAyZODBo47E+67R4jV1/gzbAkEAklJaspRPXP877NssM5nAZMU0/O/NGCZ+
  23. 3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT898jusgQJAd5Zrr6Q8
  24. AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
  25. Lw03eHTNQghS0A==
  26. -----END PRIVATE KEY-----
  27. EOD;
  28. return $cert;
  29. }
  30. public function fetch_public_cert(&$request) {
  31. $cert = <<<EOD
  32. -----BEGIN CERTIFICATE-----
  33. MIIBpjCCAQ+gAwIBAgIBATANBgkqhkiG9w0BAQUFADAZMRcwFQYDVQQDDA5UZXN0
  34. IFByaW5jaXBhbDAeFw03MDAxMDEwODAwMDBaFw0zODEyMzEwODAwMDBaMBkxFzAV
  35. BgNVBAMMDlRlc3QgUHJpbmNpcGFsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
  36. gQC0YjCwIfYoprq/FQO6lb3asXrxLlJFuCvtinTF5p0GxvQGu5O3gYytUvtC2JlY
  37. zypSRjVxwxrsuRcP3e641SdASwfrmzyvIgP08N4S0IFzEURkV1wp/IpH7kH41Etb
  38. mUmrXSwfNZsnQRE5SYSOhh+LcK2wyQkdgcMv11l4KoBkcwIDAQABMA0GCSqGSIb3
  39. DQEBBQUAA4GBAGZLPEuJ5SiJ2ryq+CmEGOXfvlTtEL2nuGtr9PewxkgnOjZpUy+d
  40. 4TvuXJbNQc8f4AMWL/tO9w0Fk80rWKp9ea8/df4qMq5qlFWlx6yOLQxumNOmECKb
  41. WpkUQDIDJEoFUzKMVuJf4KO/FJ345+BNLGgbJ6WujreoM1X/gYfdnJ/J
  42. -----END CERTIFICATE-----
  43. EOD;
  44. return $cert;
  45. }
  46. }
  47. /**
  48. * A mock store for testing
  49. */
  50. class MockOAuthDataStore extends OAuthDataStore {/*{{{*/
  51. private $consumer;
  52. private $request_token;
  53. private $access_token;
  54. private $nonce;
  55. function __construct() {/*{{{*/
  56. $this->consumer = new OAuthConsumer("key", "secret", NULL);
  57. $this->request_token = new OAuthToken("requestkey", "requestsecret", 1);
  58. $this->access_token = new OAuthToken("accesskey", "accesssecret", 1);
  59. $this->nonce = "nonce";
  60. }/*}}}*/
  61. function lookup_consumer($consumer_key) {/*{{{*/
  62. if ($consumer_key == $this->consumer->key) return $this->consumer;
  63. return NULL;
  64. }/*}}}*/
  65. function lookup_token($consumer, $token_type, $token) {/*{{{*/
  66. $token_attrib = $token_type . "_token";
  67. if ($consumer->key == $this->consumer->key
  68. && $token == $this->$token_attrib->key) {
  69. return $this->$token_attrib;
  70. }
  71. return NULL;
  72. }/*}}}*/
  73. function lookup_nonce($consumer, $token, $nonce, $timestamp) {/*{{{*/
  74. if ($consumer->key == $this->consumer->key
  75. && (($token && $token->key == $this->request_token->key)
  76. || ($token && $token->key == $this->access_token->key))
  77. && $nonce == $this->nonce) {
  78. return $this->nonce;
  79. }
  80. return NULL;
  81. }/*}}}*/
  82. function new_request_token($consumer) {/*{{{*/
  83. if ($consumer->key == $this->consumer->key) {
  84. return $this->request_token;
  85. }
  86. return NULL;
  87. }/*}}}*/
  88. function new_access_token($token, $consumer) {/*{{{*/
  89. if ($consumer->key == $this->consumer->key
  90. && $token->key == $this->request_token->key) {
  91. return $this->access_token;
  92. }
  93. return NULL;
  94. }/*}}}*/
  95. }/*}}}*/
  96. ?>