Git Product home page Git Product logo

sessitoken's Introduction

sessitoken

Handles session or token based storing with sliding expiration

Currently supplies two stores: FileStore (default) and MongoStore. FileStore saves sessions to disk in JSON format, MongoStore saves session in a MongoDB database.

##Usage

npm install sessitoken
var sessitoken = require('sessitoken'),
  restify = require('restify');

var server = restify.createServer();

var options = {
  duration: 20 * 60 * 1000, // 20 minutes - default
  activeDuration: 5 * 60 * 1000, // 5 minutes - default. If the time to expiration < active duration, it will be increased by active duration
  token: 'auth', // a header named auth will be accepted and req.auth will be set
  cookie: 'authCookie' // a cookie named authCookie will be accepted and set
};

server.use(sessitoken.sessitoken(options));

When req is passed to the route handler, req.token and req.session will have been added. Changes to req.session will be persisted when the response is finished.

Using MongoStore

sessitoken can save its sessions in MongoDB for easier access across multiple servers, for instance when using a load balancer.

var sessitoken = require('sessitoken'),
  restify = require('restify');

var server = restify.createServer();

var options = {
  duration: 20 * 60 * 1000, // 20 minutes - default
  activeDuration: 5 * 60 * 1000, // 5 minutes - default. If the time to expiration < active duration, it will be increased by active duration
  token: 'auth', // a header named auth will be accepted and req.auth will be set
  cookie: 'authCookie' // a cookie named authCookie will be accepted and set,
  store: new sessitoken.MongoStore({ 
    connectionString: 'mongodb://localhost/mydatabase', // required
    collection: 'sessions' // 'sessions' - default
  })
};

server.use(sessitoken.sessitoken(options));

sessitoken's People

Contributors

osirisguitar avatar johanobrink avatar

Watchers

 avatar James Cloos avatar

Forkers

raduachim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.