Lightweight Connect Middleware access control with tokens


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

via npm

npm install tokenator

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']))

For express

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

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

  app.use(tokenator(['5917f138c80b512d14a4ee2fe05a17dc', '7b1a47ab847f7534b507c6ae4a763118']))

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