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: 9c230c7fae

Fetching latest commit…

Cannot retrieve the latest commit at this time

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

README.rdoc

***

CONNECT-RPX IS CURRENTLY BROKEN.  
I AM TRYING TO REFACTOR OUT RESTLER AND TROUBLESHOOTING NASTY NODE JSON CRASHES.
UNFORTUNATELY, USING WITH RESTLER IS ABOUT AS BROKEN AS THE CURRENT STATE
BECAUSE RESTLER REQUIRES PATCHES TO USE WITH HTTPS, WHICH IS REQUIRED FOR RPX.
DRAT.

***

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/middleware/session/memory');
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.load

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.bodyDecoder(),
  Connect.cookieDecoder(),
  Connect.session({ 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.