You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

accountdown-token

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accountdown-token

Token authentication for accountdown

0.1.0
Source
npm
Version published
Weekly downloads
6
500%
Maintainers
1
Weekly downloads
 
Created
Source

accountdown-token NPM version

Token authentication for accountdown

Install

Install with npm

npm i accountdown-token --save

Run tests

npm test

Usage

var Token = require('accountdown-token');
var accountdown = require('accountdown');
var level = require('level');

var db = level('tmp/users.db');
var users = accountdown(db, {
  login: {
    token: Token
  }
});

users.create('doowb', { login: { username: 'doowb', token 'foobarbaz' }, value: { name: 'Brian' }}, function (err) {
  if (err) return console.log('Error creating user', err);

  users.verify('token', { username: 'doowb', token: 'foobarbaz' }, function (err, ok, id) {
    if (err) return console.log('Error', err);
    if (ok === false) return console.log('Invalid token for ' + id);
    console.log('Valid token for ' + id);
  }):
});

API

.verify

Verify that the token is correct and still valid (e.g. not expired)

  • creds {Object}: Credentials object containing a username and token to validate.
  • cb {Function}: Callback that takes err, ok, id
login.verify({ username: 'doowb', token: 'XXXXXXXXXXXX' }, function (err, ok, id) {
  if (err) return console.log('Error validating token');
  if (ok === true) return console.log('valid token for ' + id);
  console.log('Invalid token for ' + id);
});

.create

Create a new user token for the given id and credentials.

  • id {String}: Identifier of the account being created.
  • creds {Object}: Credentials object used for creating the token.
  • returns {Array}: Array of rows to be added to the [accountdown] database
login.create('doowb', { username: 'doowb' });

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Brian Woodward

License

Copyright (c) 2015 Brian Woodward
Released under the MIT license

This file was generated by verb on February 03, 2015.

FAQs

Package last updated on 03 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts