Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 7, 2018. It is now read-only.

fishbrain/tokenator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

Lightweight Connect Middleware access control with tokens

Resources

License

Stars

Watchers

Forks

Packages

No packages published