2 require_once 'common.inc.php';
5 $test_consumer = new OAuthConsumer("key", "secret", NULL);
6 $req_token = new OAuthConsumer("requestkey", "requestsecret", 1);
7 $acc_token = new OAuthConsumer("accesskey", "accesssecret", 1);
9 $sig_method = $hmac_method;
10 $user_sig_method = @$_GET['sig_method'];
11 if ($user_sig_method) {
12 $sig_method = $sig_methods[$user_sig_method];
15 $req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $base_url . "/request_token.php");
16 $req_req->sign_request($sig_method, $test_consumer, NULL);
18 $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $req_token, "GET", $base_url . "/access_token.php");
19 $acc_req->sign_request($sig_method, $test_consumer, $req_token);
21 $echo_req = OAuthRequest::from_consumer_and_token($test_consumer, $acc_token, "GET", $base_url . "/echo_api.php", array("method"=> "foo%20bar", "bar" => "baz"));
22 $echo_req->sign_request($sig_method, $test_consumer, $acc_token);
27 <title>OAuth Test Server</title>
30 <div><a href="index.php">server</a> | <a href="client.php">client</a></div>
31 <h1>OAuth Test Server</h1>
32 <h2>Instructions for Use</h2>
33 <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>
34 <h3>Your Consumer Key / Secret</h3>
36 <li>consumer key: <code><strong>key</strong></code></li>
37 <li>consumer secret: <code><strong>secret</strong></code></li>
39 <p>Use this key and secret for all your requests.</p>
40 <h3>Getting a Request Token</h3>
43 <li>request token endpoint: <code><strong><?php echo $base_url . "/request_token.php"; ?></strong></code></li>
46 <p>A successful request will return the following:</p>
47 <p><code>oauth_token=requestkey&oauth_token_secret=requestsecret</code></p>
49 <p>An unsuccessful request will attempt to describe what went wrong.</p>
52 <a href="<?php echo $req_req; ?>"><?php echo $req_req; ?></a>
54 <h3>Getting an Access Token</h3>
55 <p>The Request Token provided above is already authorized, you may use it to request an Access Token right away.</p>
58 <li>access token endpoint: <code><strong><?php echo $base_url . "/access_token.php"; ?></strong></code></li>
61 <p>A successful request will return the following:</p>
62 <p><code>oauth_token=accesskey&oauth_token_secret=accesssecret</code></p>
64 <p>An unsuccessful request will attempt to describe what went wrong.</p>
67 <a href="<?php echo $acc_req; ?>"><?php echo $acc_req; ?></a>
69 <h3>Making Authenticated Calls</h3>
70 <p>Using your Access Token you can make authenticated calls.</p>
73 <li>api endpoint: <code><strong><?php echo $base_url . "/echo_api.php"; ?></strong></code></li>
76 A successful request will echo the non-OAuth parameters sent to it, for example:</p>
77 <p><code>method=foo&bar=baz</code></p>
78 <p>An unsuccessful request will attempt to describe what went wrong.</p>
81 <a href="<?php echo $echo_req; ?>"><?php echo $echo_req; ?></a>
83 <h3>Currently Supported Signature Methods</h3>
84 <p>Current signing method is: <?php echo $user_sig_method ?></p>
87 $sig_methods = $test_server->get_signature_methods();
88 foreach ($sig_methods as $key => $method) {
90 if ($key != $sig_method->get_name()) {
91 print "(<a href='?sig_method=$key'>switch</a>)";
99 if ("RSA-SHA1" == $sig_method->get_name()) {
100 print "<pre>" . $sig_method->fetch_private_cert($req_req) . "</pre>\n";
101 print "<pre>" . $sig_method->fetch_public_cert($req_req) . "</pre>\n";
105 <h3>Further Resources</h3>
106 <p>There is also a <a href="client.php">test client</a> implementation in here.</p>
107 <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>