Git Product home page Git Product logo

mediawiki-oauthclient-php's Introduction

Latest Stable Version License

mediawiki/oauthclient

PHP OAuth client for use with Wikipedia and other MediaWiki-based wikis running the OAuth extension.

Installation

$ composer require mediawiki/oauthclient

Usage

For working example code, see the demo directory.

General usage is as follows:

  1. Create a new Client with consumer key that you've registered with the wiki. Setting an user agent is highly encouraged.

    $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 );
    
  2. Retrieve the authentication URL and the Request Token:

    list( $authUrl, $requestToken ) = $client->initiate();
    
  3. Store the Request Token somewhere and send the user to the authentication URL.

  4. When the user comes back from the wiki they'll arrive at your callback URL, and the query string will contain an oauth_verifier key. Use this to retrieve an Acccess Token:

    $accessToken = $client->complete( $requestToken,  $_GET['oauth_verifier'] );
    
  5. 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"
    );
    

Running tests

composer install --prefer-dist
composer test

History

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.


mediawiki-oauthclient-php's People

Contributors

0x010c avatar atdt avatar bd808 avatar daimona avatar ebernhardson avatar glazermann avatar jdforrester avatar legoktm avatar octfx avatar reedy avatar samwilson avatar supertassu avatar tgr avatar umherirrender avatar urbanecm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.