Skip to content

joewagner/redis-ticket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Ticket

simple implementation of a single use "ticket". This module exposes key: value set and get methods. key must be a String, and value can be anything. The get method returns the value then deletes the key:value from the store. This is useful for building 3 party ticket based authentication tools.

Installation

npm install redis-ticket

Options

Example

const RedisTicket = require('redis-ticket');

const ticketStore = new RedisTicket({
    // NOTE: for most cases should not have to specify any options
    prefix: 'socket-tickets:',
    port: 6379
});

// ...

    // after authenticating `user`
    const key = getUUID(); // function that returns a universally unique ID, e.g. UUID V4
    await ticketStore.set(key, {_id: user._id});

// elsewhere..
io.use(function (socket, next) {
    // already authenticated
    if (socket.user) return next();

    var ticket = socket.handshake.query && socket.handshake.query.authticket;
    if (ticket) {
        const user = await ticketStore.get(ticket);
        const userId = user && user._id

        // get user from db and attach to socket...

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published