Lightweight Connect Middleware access control with tokens
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

Tokenator

Build Status

Tokenator is a lightweight piece of Connect Middleware to provide access control based on a token. It is design to be used with APIs.

Installation

via npm

npm install tokenator

Usage

Tokenator expects the API token to be sent by the client in a header named 'api-token'.

On the server tokenator expects an array of valid tokens.

If a client tries to connect without a token or an invalid token a 401 response will be returned.

For connect

var connect = require('connect'),
    http = require('http'),
    tokenator = require('tokenator');

function accessGranted(req, res){
  res.end('Tokenator says yes!');
}
var app = connect()
  .use(tokenator(['5917f138c80b512d14a4ee2fe05a17dc', '7b1a47ab847f7534b507c6ae4a763118']))
  .use(accessGranted)

http.Server(app).listen(3000);

For express

var express = require('express'),
    tokenator = require('tokenator');

var app = module.exports = express.createServer();

app.configure(function(){
  app.use(tokenator(['5917f138c80b512d14a4ee2fe05a17dc', '7b1a47ab847f7534b507c6ae4a763118']))
});

app.get('/', function(req, res){
  res.send('Tokenator says yes!');
});

app.listen(3000);