Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Use RPX with Connect on top of Node.js
JavaScript
tree: 9403e2fca7

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
README.rdoc
login.html
package.json

README.rdoc

connect-rpx.js

Use RPX with Connect on top of Node.js nodejs.org/ github.com/extjs/Connect

Usage:

// Setup whatever require paths you need.  You'll need to at least make restler accessible to connect-rpx
// require.paths.unshift('../node-lib/connect-rpx'); // This might work!
// require.paths.unshift('../node-lib/restler/lib'); // And, something like this!
var Connect = require('connect');
var MemoryStore = require('connect/lib/connect/middleware/session/memory').MemoryStore;
var RPX = require( 'rpx' );

// Setup RPX 
// 
// Your API key, look in the settings on rpxnow.com
RPX.config( 'apiKey', 'abcefgehijk' );
// (Specify root paths to ignore, paths not protected by RPX auth, or paths you need to serve for your login page, like CSS)
RPX.config( 'ignorePaths', [ '/stylesheets', '/images', '/javascript', '/css' ] );
// This is where RPX will redirect you to once authentication has occurred
RPX.config( 'reentryPoint',  '/rpx_login' );
// This will remove the user auth session cookie, effectively logging you out.
RPX.config( 'logoutPoint',  '/logout' );
// The page which you use as a login page, see the sample login.html here.
RPX.config( 'loginPage',  '/static/login.html' );

// 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.bodyDecoder(),
    Connect.redirect(),
    Connect.cookieDecoder(),
    Connect.session({ store: new MemoryStore({ reapInterval: minute, maxAge: minute * 5 }) }),
    RPX.handler,
    Connect.staticProvider( root )  // this is not strictly required, 
                                    // but might be where you store login page and CSS, etc.
);
  • 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 );

TODO:

  • 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.…

THANKS

This code was based on the rack-rpx module github.com/pedrodelgallego/rack-rpx

Something went wrong with that request. Please try again.