Use RPX with Connect on top of Node.js nodejs.org/ github.com/extjs/Connect
var Connect = require('connect');
var MemoryStore = require('connect').session.MemoryStore;
var RPX = require( 'connect-rpx' );
// Setup RPX
// Your API key, look in the settings on rpxnow.com
RPX.config( 'apiKey', 'asdasdadadadadasdasdasd' );
RPX.config( 'ignorePaths', [ '/stylesheets', '/images', '/javascript', '/css', "/login" ] );
RPX.config( 'reentryPoint', '/rpx_login' );
RPX.config( 'logoutPoint', '/logout' );
RPX.config( 'loginPage', '/login/index.html' );
RPX.config( 'onSuccessfulLogin', handleLogin );
// Or, just load from JSON
RPX.loadConfig( "./config.json" );
function redirect(res,location) {
res.writeHead( 302, {
‘Location’: location
});
res.end();
}
function handleLogin( json, req, res, next ) {
req.sessionStore.regenerate(req, function(err){
req.session.profile = json.profile; req.session.username = json.profile.displayName; // next();
});
redirect( res, '/' );
}
// Setup your connect. RPX requires session, cookieDecoder, redirect installed before RPX.
var minute = 60000;
var root = __dirname + "/public";
var Server = module.exports = Connect.createServer(
Connect.logger(),
Connect.cookieDecoder(),
Connect.session({ secret: 'your_secrets_safe_with_me', store: new MemoryStore({ reapInterval: minute, maxAge: minute * 5 }) }),
RPX.handler(),
Connect.staticProvider( root ) // this is not strictly required, );
Server.listen(3030);
-
Then, run your app, and it should redirect to you the loginPath specified in the configuration.
// You can access the username by using req.session.username inside your app var username = req.session.username;
-
Need to test locally? This will enable a random user login rather than going into RPX for authentication allowing you to test while on a plane and simulate a login.
// Add this after the last RPX.config line // DON'T FORGET TO REMOVE THIS IN PRODUCTION!!! RPX.config( 'fakedAuthentication', true );
-
Remove dependency on restler
-
Install a callback to add other data beyond just username into the session
-
Add something to better handle errors or cancellations
-
Write test cases, I’m so embarassed to publish without them.…
This code was based on the rack-rpx module github.com/pedrodelgallego/rack-rpx