Skip to content

Commit 7f2b1a0

Browse files
author
csteipp
committed
Add comments to demo app to explain what's happening
1 parent 22d2993 commit 7f2b1a0

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

demo.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,36 @@
55
$consumerKey = 'b02833d71fe5700c891c531fe041c36c';
66
$consumerSecret = 'f2b6f6ccc47e9f6b298eaa74789897b98dc6a594';
77

8-
$config = new MWOAuthClientConfig( 'https://localhost/wiki/index.php?title=Special:OAuth', true, false );
8+
// Configure the connection to the wiki you want to use. Passing title=Special:OAuth as a
9+
// GET parameter makes the signature easier. Otherwise you need to call
10+
// $client->setExtraParam('title','Special:OAuth/whatever') for each step.
11+
// If your wiki uses wgSecureLogin, the canonicalServerUrl will point to http://
12+
$config = new MWOAuthClientConfig(
13+
'https://localhost/wiki/index.php?title=Special:OAuth', // url to use
14+
true, // do we use SSL? (we should probably detect that from the url)
15+
false // do we validate the SSL certificate? Always use 'true' in production.
16+
);
917
$config->canonicalServerUrl = 'http://localhost';
18+
1019
$cmrToken = new OAuthToken( $consumerKey, $consumerSecret );
1120
$client = new MWOAuthClient( $config, $cmrToken );
21+
22+
// Step 1 - Get a request token
1223
list( $redir, $requestToken ) = $client->initiate();
1324

25+
// Step 2 - Have the user authorize your app. Get a verifier code from them.
26+
// (if this was a webapp, you would redirect your user to $redir, then use the 'oauth_verifier'
27+
// GET parameter when the user is redirected back to the callback url you registered.
1428
echo "Point your browser to: $redir\n\n";
1529
print "Enter the verification code:\n";
1630
$fh = fopen( "php://stdin", "r" );
17-
$line = fgets( $fh );
31+
$verifyCode = trim( fgets( $fh ) );
32+
33+
// Step 3 - Exchange the request token and verification code for an access token
34+
$accessToken = $client->complete( $requestToken, $verifyCode );
35+
36+
// You're done! You can now identify the user, and/or call the API (examples below) with $accessToken
1837

19-
$accessToken = $client->complete( $requestToken, trim( $line ) );
2038

2139
// If we want to authenticate the user
2240
$identity = $client->identify( $accessToken );

0 commit comments

Comments
 (0)