Comparing version 0.1.5 to 0.2.0
@@ -67,3 +67,3 @@ //Global variables | ||
if (p == response[config.key]) { | ||
return next() | ||
valid = true | ||
} else { | ||
@@ -73,2 +73,6 @@ return false | ||
}) | ||
//The user is authorized | ||
if (valid === true) { | ||
return next() | ||
} | ||
} else { | ||
@@ -75,0 +79,0 @@ if (permissions === response[config.key]) { |
{ | ||
"name": "redis.auth", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "A non prescriptive Redis Authentication module for Express", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,2 +33,26 @@ [![Build Status](https://travis-ci.org/ChrisCates/redis.auth.svg?branch=master)](https://travis-ci.org/ChrisCates/redis.auth) | ||
### 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) { | ||
return res.status(200).send("Only users can access this...") | ||
}) | ||
//Example multi user permission | ||
app.get("/user", auth(["user", "admin"]), function(req,res) { | ||
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: | ||
@@ -35,0 +59,0 @@ #### With returnError = true |
45
tests.js
@@ -78,2 +78,6 @@ //Uncache the auth module | ||
app.get("/auth_multi", auth(["user", "admin"]), function(req,res) { | ||
return res.status(200).send("Authorized :)") | ||
}) | ||
app.get("/auth_admin", auth("admin"), function(req,res) { | ||
@@ -137,2 +141,11 @@ return res.status(200).send("Authorized :)") | ||
it('Authenticate with middleware - multi user', function (done) { | ||
request(app) | ||
.get("/auth_multi") | ||
.set("Authorization", token) | ||
.expect(200, "Authorized :)", done) | ||
}) | ||
it('Authenticate with middleware for admin', function (done) { | ||
@@ -147,2 +160,11 @@ | ||
it('Authenticate with middleware for admin - multi user', function (done) { | ||
request(app) | ||
.get("/auth_multi") | ||
.set("Authorization", token2) | ||
.expect(200, "Authorized :)", done) | ||
}) | ||
it('Should return a 403 - No header supplied', function (done) { | ||
@@ -180,2 +202,7 @@ | ||
app.get("/auth2_multi", auth2(["user", "admin"]), function(req,res) { | ||
if (req.errorCode == 403) return res.status(req.errorCode).send("Unauthorized...") | ||
return res.status(200).send("Authorized :)") | ||
}) | ||
app.get("/auth2_admin", auth2("admin"), function(req,res) { | ||
@@ -195,2 +222,11 @@ if (req.errorCode == 403) return res.status(req.errorCode).send("Unauthorized...") | ||
it('Authenticate with middleware - multi user', function (done) { | ||
request(app) | ||
.get("/auth2_multi") | ||
.set("Authorization", token) | ||
.expect(200, "Authorized :)", done) | ||
}) | ||
it('Authenticate with middleware for admin', function (done) { | ||
@@ -205,2 +241,11 @@ | ||
it('Authenticate with middleware for admin - multi user', function (done) { | ||
request(app) | ||
.get("/auth2_multi") | ||
.set("Authorization", token2) | ||
.expect(200, "Authorized :)", done) | ||
}) | ||
it('Should return a 403 - No header supplied', function (done) { | ||
@@ -207,0 +252,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31116
295
79