index.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. require_once("common.inc.php");
  3. $test_consumer = new OAuthConsumer("key", "secret", NULL);
  4. $req_token = new OAuthConsumer("requestkey", "requestsecret", 1);
  5. $acc_token = new OAuthConsumer("accesskey", "accesssecret", 1);
  6. $sig_method = $hmac_method;
  7. $user_sig_method = @$_GET['sig_method'];
  8. if ($user_sig_method) {
  9. $sig_method = $sig_methods[$user_sig_method];
  10. }
  11. $req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $base_url . "/request_token.php");
  12. $req_req->sign_request($sig_method, $test_consumer, NULL);
  13. $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $req_token, "GET", $base_url . "/access_token.php");
  14. $acc_req->sign_request($sig_method, $test_consumer, $req_token);
  15. $echo_req = OAuthRequest::from_consumer_and_token($test_consumer, $acc_token, "GET", $base_url . "/echo_api.php", array("method"=> "foo%20bar", "bar" => "baz"));
  16. $echo_req->sign_request($sig_method, $test_consumer, $acc_token);
  17. ?>
  18. <html>
  19. <head>
  20. <title>OAuth Test Server</title>
  21. </head>
  22. <body>
  23. <div><a href="index.php">server</a> | <a href="client.php">client</a></div>
  24. <h1>OAuth Test Server</h1>
  25. <h2>Instructions for Use</h2>
  26. <p>This is a test server with a predefined static set of keys and tokens, you can make your requests using them to test your code (and mine ;)).</p>
  27. <h3>Your Consumer Key / Secret</h3>
  28. <ul>
  29. <li>consumer key: <code><strong>key</strong></code></li>
  30. <li>consumer secret: <code><strong>secret</strong></code></li>
  31. </ul>
  32. <p>Use this key and secret for all your requests.</p>
  33. <h3>Getting a Request Token</h3>
  34. <ul>
  35. <li>request token endpoint: <code><strong><?php echo $base_url . "/request_token.php"; ?></strong></code></li>
  36. </ul>
  37. <p>A successful request will return the following:</p>
  38. <p><code>oauth_token=requestkey&amp;oauth_token_secret=requestsecret</code></p>
  39. <p>An unsuccessful request will attempt to describe what went wrong.</p>
  40. <h4>Example</h4>
  41. <a href="<?php echo $req_req; ?>"><?php echo $req_req; ?></a>
  42. <h3>Getting an Access Token</h3>
  43. <p>The Request Token provided above is already authorized, you may use it to request an Access Token right away.</p>
  44. <ul>
  45. <li>access token endpoint: <code><strong><?php echo $base_url . "/access_token.php"; ?></strong></code></li>
  46. </ul>
  47. <p>A successful request will return the following:</p>
  48. <p><code>oauth_token=accesskey&amp;oauth_token_secret=accesssecret</code></p>
  49. <p>An unsuccessful request will attempt to describe what went wrong.</p>
  50. <h4>Example</h4>
  51. <a href="<?php echo $acc_req; ?>"><?php echo $acc_req; ?></a>
  52. <h3>Making Authenticated Calls</h3>
  53. <p>Using your Access Token you can make authenticated calls.</p>
  54. <ul>
  55. <li>api endpoint: <code><strong><?php echo $base_url . "/echo_api.php"; ?></strong></code></li>
  56. </ul>
  57. <p>
  58. A successful request will echo the non-OAuth parameters sent to it, for example:</p>
  59. <p><code>method=foo&amp;bar=baz</code></p>
  60. <p>An unsuccessful request will attempt to describe what went wrong.</p>
  61. <h4>Example</h4>
  62. <a href="<?php echo $echo_req; ?>"><?php echo $echo_req; ?></a>
  63. <h3>Currently Supported Signature Methods</h3>
  64. <p>Current signing method is: <?php echo $user_sig_method ?></p>
  65. <ul>
  66. <?php
  67. $sig_methods = $test_server->get_signature_methods();
  68. foreach ($sig_methods as $key => $method) {
  69. print "<li>$key";
  70. if ($key != $sig_method->get_name()) {
  71. print "(<a href='?sig_method=$key'>switch</a>)";
  72. }
  73. print "</li>\n";
  74. }
  75. ?>
  76. </ul>
  77. <?php
  78. if ("RSA-SHA1" == $sig_method->get_name()) {
  79. print "<pre>" . $sig_method->fetch_private_cert($req_req) . "</pre>\n";
  80. print "<pre>" . $sig_method->fetch_public_cert($req_req) . "</pre>\n";
  81. }
  82. ?>
  83. <h3>Further Resources</h3>
  84. <p>There is also a <a href="client.php">test client</a> implementation in here.</p>
  85. <p>The code running this example can be downloaded from the PHP section of the OAuth google code project: <a href="http://code.google.com/p/oauth/">http://code.google.com/p/oauth/</a>
  86. </body>