Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Use RPX with Connect on top of Node.js

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 lib
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 package.json
README.rdoc

connect-rpx.js

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

Usage:

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 );

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.