express-masquerade

0.1.2 • Public • Published

express-masquerade

NPM Version NPM Downloads Node.js Version Build Status Coverage Status Gittip

Masquerade as other users via x-masquerade-as header middleware. Plays well with passport.

Add it as middleware. The first parameter is a function that gets a user by id:

var express = require('express');
var masquerade = require('express-masquerade');
 
var app = express();
 
app.use(masquerade(function(id, next) {
  User.find(id).complete(next);
}));

This will set req.user to the user with an id of 2:

curl localhost:3000/profile --header "x-masquerade-as: 2"

Installation

$ npm install express-masquerade

Options

Pass options as the second parameter:

app.use(require('express-masquerade')(getUser, options));

header (string)

Use a different header than x-masquerade-as.

var options = {
  header: 'masquerading-as'
};

authorize (function)

Set a function to authorize whether or not the user has permission to masquerade. Should return true or false.

var options = {
  authorize: function(req) {
    return req.user.role === 'admin';
  }
};

MIT Licensed

Package Sidebar

Install

npm i express-masquerade

Weekly Downloads

7

Version

0.1.2

License

MIT

Last publish

Collaborators

  • cjroth