mediawiki/oauthclient-php
PHP OAuth client to use with Wikipedia and other MediaWiki-based wikis running the OAuth extension.
|
![Latest Stable Version] ![License]
PHP OAuth client for use with Wikipedia and other MediaWiki-based wikis running the OAuth extension.
$ composer require mediawiki/oauthclient
For working example code, see the demo directory.
General usage is as follows:
$conf = new ClientConfig( 'https://example.org/w/index.php?title=Special:OAuth' ); $conf->setConsumer( new Consumer( 'e331e186b64a938591e7614170814a75', '9b61abdfa2b88f05670af3919302b12bbc6a6e10' ) ); $conf->setUserAgent( 'MyCoolApp MediaWikiOAuthClient/1.0' ); $client = new Client( $conf );
list( $authUrl, $requestToken ) = $client->initiate();
oauth_verifier
key. Use this to retrieve an Acccess Token: $accessToken = $client->complete( $requestToken, $_GET['oauth_verifier'] );
Once you've got an Access Token you can store it and use it to make authenticated requests to the wiki.
To get the user's identity:
$ident = $client->identify( $accessToken );
To make any API call:
$userInfo = $client->makeOAuthCall( $accessToken, "https://example.org/w/api.php?action=query&meta=userinfo&uiprop=rights&format=json" );
composer install –prefer-dist composer test
The code is a refactored version of Stype/mwoauth-php, which in turn is partially based on Andy Smith's OAuth library. Some code is taken from wikimedia/slimapp. See CHANGELOG.md for more details.