Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-express-middleware

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-express-middleware

Use express middleware outside of express.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

use-express-middleware

The main purpose of this module is to use express middleware for authentication in deepstream.io.

If you find other uses for this module, please let me know.

Install:

npm install use-express-middleware --save

Tested Middleware:

✓ express-session
✓ passport.initialize()
✓ passport.session()

Usage:

Deepstream passport authentication:

import Deepstream from 'deepstream.io'
import useExpressMiddleware from 'use-express-middleware'
import expressSession from 'express-session'
import passport from 'passport'

const server = new Deepstream()

// You can define this somewhere in your app and then import it both
//  for express and deepstream.
// If you use a store such as redis for you sessions, you'll be able
//  to run express and deepstream in two seperate processes and/or on
//  two seperate ports if you so please.
const session = expressSession({
  ...options
})

const middleware = [session, passport.initialize(), passport.session()]

// Using a callback:
server.set('permissionHandler', {
  isValidUser(connectionData, authData, callback) {
    useExpressMiddleware(connectionData.headers, middleware, (req, res) => {
      if(req.user) {
        callback(null, req.user.id)
      } else {
        callback(null, 'open')
      }
    })
  },

  canPerformAction(id, message, callback) {
    const user = getUserFromId(id)  // pseudo code

    callback(null, user.isAdmin)
  }
})

// Using promises and async/await:
server.set('permissionHandler', {
  isValidUser: async (connectionData, authData, callback) => {
    const {req, res} = await useExpressMiddleware(connectionData.headers, middleware)

    if(req.user) {
      callback(null, req.user.id)
    } else {
      callback(null, 'open')
    }
  },

  ...
})

How does this work?

TODO

FAQs

Package last updated on 07 Apr 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc