|
5 | 5 | $consumerKey = 'b02833d71fe5700c891c531fe041c36c'; |
6 | 6 | $consumerSecret = 'f2b6f6ccc47e9f6b298eaa74789897b98dc6a594'; |
7 | 7 |
|
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 | +); |
9 | 17 | $config->canonicalServerUrl = 'http://localhost'; |
| 18 | + |
10 | 19 | $cmrToken = new OAuthToken( $consumerKey, $consumerSecret ); |
11 | 20 | $client = new MWOAuthClient( $config, $cmrToken ); |
| 21 | + |
| 22 | +// Step 1 - Get a request token |
12 | 23 | list( $redir, $requestToken ) = $client->initiate(); |
13 | 24 |
|
| 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. |
14 | 28 | echo "Point your browser to: $redir\n\n"; |
15 | 29 | print "Enter the verification code:\n"; |
16 | 30 | $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 |
18 | 37 |
|
19 | | -$accessToken = $client->complete( $requestToken, trim( $line ) ); |
20 | 38 |
|
21 | 39 | // If we want to authenticate the user |
22 | 40 | $identity = $client->identify( $accessToken ); |
|
0 commit comments