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

redis.auth

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis.auth

A non prescriptive Redis Authentication module for Express

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

NPM

redis.auth

A non prescriptive Redis Authentication module for Express

By Chris Cates :star:

Installation

npm install redis.auth --save

Configuration

Note that it requires redis.token npm module to work properly

var redis = require("redis.token")()
var auth = require("redis.auth")(redis, {
  //Check for which Express header use when authenticating the client
  "header": "authorization",
  //The key in the redis session storage you want to check for
  "key": "grantType",
  //If return error is true it sends a 403 or 500 status based on the error
  //Turn this off if you want to do your own error checking
  "returnError": true
})

Example Express middleware

var express = require("express")
var app = express()

var auth = require("redis.auth")()

//Example single user permission
app.get("/user", auth("user"), function(req,res) {
  //req.auth = stored Redis.Token Object
  return res.status(200).send("Only users can access this...")
})

//Example multi user permission
app.get("/user", auth(["user", "admin"]), function(req,res) {
  //req.auth = stored Redis.Token Object 
  return res.status(200).send("Admins and users can access this...")
})

/*
** Assuming the following is in the redis token
** { grantType: user }
** And the header has a valid Redis token...
*/

Example status returns:

With returnError = true
return res.status(403).send({
  "error": true,
  "status": 403,
  "message": "No "+config.header+" header supplied..."
})
With returnError = false
//Sets these variables in req so you can check for them on your own
req.error = true
req.errorType = "No "+config.header+" header supplied..."
req.errorCode = 403
return next()
Questions, email hello@chriscates.ca

Keywords

FAQs

Package last updated on 02 May 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