Socket
Socket
Sign inDemoInstall

express-masquerade

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-masquerade

masquerade as other users


Version published
Weekly downloads
4
Maintainers
1
Install size
3.19 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 10 Sep 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc