Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including passport-mediawiki-oauth with all npm packages installed. Try it out:

var passportMediawikiOauth = require("passport-mediawiki-oauth")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

passport-mediawiki-oauth v0.1.0

MediaWiki (OAuth) authentication strategies for Passport.

Passport-MediaWiki-OAuth

Passport strategies for authenticating with MediaWiki using OAuth 1.0a. Documentation and code shamelessly adapted from Jared Hanson's Passport-Google-OAuth.

This module lets you authenticate using MediaWiki in your Node.js applications. By plugging into Passport, MediaWiki authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-mediawiki-oauth

Usage of OAuth 1.0

Configure Strategy

The MediaWiki OAuth 1.0 authentication strategy authenticates users using a MediaWiki account and OAuth tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a consumer key, consumer secret, and callback URL.

var MediaWikiStrategy = require('passport-mediawiki-oauth').OAuthStrategy;

passport.use(new MediaWikiStrategy({
    consumerKey: MEDIAWIKI_CONSUMER_KEY,
    consumerSecret: MEDIAWIKI_CONSUMER_SECRET,
    callbackURL: MEDIAWIKI_CALLBACK_URL
  },
  function(token, tokenSecret, profile, done) {
    User.findOrCreate({ mediawikiGlobalId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'mediawiki' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/mediawiki',
  passport.authenticate('mediawiki', { scope: MEDIAWIKI_AUTH_SCOPE }));

app.get('/auth/mediawiki/callback', 
  passport.authenticate('mediawiki', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Examples

For a complete, working example, refer to the OAuth 1.0 example. To get it up and running, you can do:

$ cd examples/oauth
$ npm install
$ node app.js

Tests

$ npm install --dev
$ make test

Build Status

Credits

License

The MIT License

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free