node package manager

passport-trademe

Trade Me (www.trademe.co.nz) authentication strategy for Passport.

passport-trademe

Trade Me authentication strategy for Passport.

  [sudo] npm install passport-trademe

Fame, fortune ... free beer.

Very simple ...

var passport = require( 'passport' )
, TrademeStrategy = require( 'passport-trademe' ).Strategy
...
var trademeKey = require( './keys/trademeKey' );
passport.use(new TrademeStrategy( {
consumerKey: trademeKey.consumerKey
, consumerSecret: trademeKey.consumerSecret
, callbackURL: app.get( 'site-url' ) + '/auth/trademe/callback'
}
, function( tokentokenSecretprofiledone ) {
...
}
) );
...
app.configure( function() {
app.use( passport.initialize() );
app.use( passport.session() );
app.use( app.router );
} );

Define you "conversation" routes ...

app.get( '/auth/trademe'
, passport.authenticate( 'trademe'
, { 
// Add the scope of your application here 
scope: [ 'MyTradeMeRead'
, 'MyTradeMeWrite'
, 'BiddingAndBuying' ] 
} 
)
, function( reqres ) {
// Nothing to do here. The "conversation" will end at the callback route. 
} );
app.get( '/auth/trademe/callback' 
, passport.authenticate( 'trademe' 
, {
failureRedirect: '/login'
}
)
, function( reqres ) {
res.redirect( '/' );
} );

Use to protect something ...

function ensureAuthenicated = function( reqresnext ) {
if ( req.isAuthenticated() ) { 
return next(); 
}
res.redirect( '/login' )
}
...
app.get( '/someProtectedResource'
, ensureAuthenticated
, function ( reqres ) {
res.redirect( '/' );
} );

Author: Cleave Pokotea