2 require_once 'common.inc.php';
4 $key = @$_REQUEST['key'];
5 $secret = @$_REQUEST['secret'];
6 $token = @$_REQUEST['token'];
7 $token_secret = @$_REQUEST['token_secret'];
8 $endpoint = @$_REQUEST['endpoint'];
9 $action = @$_REQUEST['action'];
10 $dump_request = @$_REQUEST['dump_request'];
11 $user_sig_method = @$_REQUEST['sig_method'];
12 $sig_method = $hmac_method;
13 if ($user_sig_method) {
14 $sig_method = $sig_methods[$user_sig_method];
17 $test_consumer = new OAuthConsumer($key, $secret, NULL);
21 $test_token = new OAuthConsumer($token, $token_secret);
25 if ($action == "request_token") {
26 $parsed = parse_url($endpoint);
28 parse_str($parsed['query'], $params);
30 $req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $endpoint, $params);
31 $req_req->sign_request($sig_method, $test_consumer, NULL);
33 Header('Content-type: text/plain');
34 print "request url: " . $req_req->to_url(). "\n";
38 Header("Location: $req_req");
40 else if ($action == "authorize") {
41 $callback_url = "$base_url/client.php?key=$key&secret=$secret&token=$token&token_secret=$token_secret&endpoint=" . urlencode($endpoint);
42 $auth_url = $endpoint . "?oauth_token=$token&oauth_callback=".urlencode($callback_url);
44 Header('Content-type: text/plain');
45 print("auth_url: " . $auth_url);
48 Header("Location: $auth_url");
50 else if ($action == "access_token") {
51 $parsed = parse_url($endpoint);
53 parse_str($parsed['query'], $params);
55 $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, "GET", $endpoint, $params);
56 $acc_req->sign_request($sig_method, $test_consumer, $test_token);
58 Header('Content-type: text/plain');
59 print "request url: " . $acc_req->to_url() . "\n";
63 Header("Location: $acc_req");
69 <title>OAuth Test Client</title>
72 <div><a href="index.php">server</a> | <a href="client.php">client</a></div>
73 <h1>OAuth Test Client</h1>
74 <h2>Instructions for Use</h2>
75 <p>This is a test client that will let you test your OAuth server code. Enter the appropriate information below to test.</p>
76 <p>Note: we don't store any of the information you type in.</p>
78 <form method="POST" name="oauth_client">
79 <h3>Choose a Signature Method</h3>
80 <select name="sig_method">
82 foreach ($sig_methods as $name=> $method) {
84 if ($name == $sig_method->get_name()) {
85 $selected = " selected='selected'";
87 print "<option value='$name'$selected>$name</option>\n";
91 <h3>Enter The Endpoint to Test</h3>
92 endpoint: <input type="text" name="endpoint" value="<?php echo $endpoint; ?>" size="100"/><br />
93 <small style="color: green">Note: You can include query parameters in there to have them parsed in and signed too</small>
94 <h3>Enter Your Consumer Key / Secret</h3>
95 consumer key: <input type="text" name="key" value="<?php echo $key; ?>" /><br />
96 consumer secret: <input type="text" name="secret" value="<?php echo $secret;?>" /><br />
97 dump request, don't redirect: <input type="checkbox" name="dump_request" value="1" <?php if ($dump_request) echo 'checked="checked"'; ?>/><br />
98 make a token request (don't forget to copy down the values you get)
99 <input type="submit" name="action" value="request_token" />
100 <h3>Enter Your Request Token / Secret</h3>
101 token: <input type="text" name="token" value="<?php echo $token; ?>" /><br />
102 token secret: <input type="text" name="token_secret" value="<?php echo $token_secret; ?>" /><br />
103 <p><strong>Don't forget to update your endpoint to point at the auth or access token url</strong></p>
104 try to authorize this token: <input type="submit" name="action" value="authorize" /><br />
105 try to get an access token: <input type="submit" name="action" value="access_token" /><br />
107 <h3>Currently Supported Signature Methods</h3>
108 <p>Current signing method is: <?php echo $sig_method->get_name() ?></p>
111 foreach ($sig_methods as $key => $method) {
114 if ($key != $sig_method->get_name()) {
115 print "(<a href='?sig_method=$key'>switch</a>)";
123 if ("RSA-SHA1" == $sig_method->get_name()) {
124 // passing test_server as a dummy referecne
125 print "<pre>" . $sig_method->fetch_private_cert($test_server). "</pre>\n";
126 print "<pre>" . $sig_method->fetch_public_cert($test_server) . "</pre>\n";
130 <h3>Further Resources</h3>
131 <p>There is also a <a href="index.php">test server</a> implementation in here.</p>
132 <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>