npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

admit-one

v0.3.1

Published

Adaptable Authentication

Downloads

18

Readme

Admit One

NPM version Build status Code Climate Coverage Status Dependencies devDependencies

Admit One is an adaptable authentication and authorization system for Node.js applications that require token based authentication. It aims to be incredibly easy to configure with varying databases, ORM tools, and front end frameworks.

Available Adapters

Backend

Frontend

Usage

The following example uses admit-one-mongo.

var admit = require('admit-one')('mongo', {
  mongo: {
    db: 'mongodb://localhost/dbname'
  }
});

var app = express();
var api = express.Router();

app.use(require('body-parser').json());

api.post('/users', admit.create, function(req, res) {
  // user representations accessible via
  // req.auth.user & req.auth.db.user
  res.json({ user: req.auth.user });
});

api.post('/sessions', admit.authenticate, function(req, res) {
  // user accessible via req.auth
  res.json({ session: req.auth.user });
});

// all routes defined below this line will require authorization
api.use(admit.authorize);
api.delete('/sessions/current', admit.invalidate, function(req, res) {
  if (req.auth.user) { throw new Error('Session not invalidated.'); }
  res.json({ status: 'ok' });
});

// application routes
app.use('/api', api);

Comparison to Passport

This project differs from Passport in that it defines a single strategy for user creation, authentication, and authorization. That strategy is what Passport refers to as a basic strategy. Unfortunately, though, Passport leaves it up to developers to properly handle the secure storage of passwords during user creation and properly verifying passwords during authentication when using a basic strategy. Ideally, most of this repetitive work would not need to be handled by every project individually, and that's where Admit One comes in.

Admit One does not support other strategies besides basic authentication and authorization. If you need support for something like OAuth, use Passport.

API

admit([options])

options.username

Type: String
Default: 'username'

options.password

Type: String
Default: 'password'

options.passwordDigest

Type: String
Default: 'passwordDigest'

options.params.create.username

Type: String
Default: 'user[username]'

options.params.create.password

Type: String
Default: 'user[password]'

options.params.authenticate.username

Type: String
Default: 'session[username]'

options.params.authenticate.password

Type: String
Default: 'session[password]'

options.bcryptRounds

Type: Number
Default: 12

Security

There are a few places that this project can be improved in terms of security:

  • Longer tokens could be issued or the token could be signed to prevent an attacker from more easily performing a brute force attack against the token generation algorithm
  • Tokens could be expired after a set amount of time for increased security

These points are not flaws that should affect the security of your users' data and will not prevent your application from running securely.

Example Project

There's an example app that uses admit-one-bookshelf and admit-one-ember that could be a helpful starting place.

License

This project is distributed under the MIT license.