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

authonice

v0.0.6

Published

authnice backend for nodejs, mongoose & express

Downloads

1

Readme

authonice logo

authonice (nodejs)

IN PROGRESS: not ready, yet

This is the authonice backend for nodejs, mongoose & express.

npm Build Status Code Climate

authonice is a platform/language/framework agnostic ecosystem for web-app authentication, with lots of inspiration from satellizer.

It's designed to work with lots of backend languages, auth services, & frontend frameworks. It's goal is to make you super-happy because your sites are safe, easy to setup & maintain, and stylishly locked-down in your language/frameworks of choice.

If we don't have a module for the frontend-framework/backend-language/auth-service you want to support, ask us or contribute!

You can see a demo of this in-use, here

installation

npm install authonice

usage

var express = require('express');
var app = express();
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/quickstart');
var authonice = require('authonice');
var Email = require('mongoose-type-email');

// Your User model with the default fields
var UserSchema = new mongoose.Schema({
    email: {type: Email, required:true, unique:true},
    password: {type: String, required:true},
    verify: {type:String, default:null}
});
UserSchema.plugin(require('mongoose-bcrypt'));
var User = module.exports = mongoose.model('User', UserSchema);

// mount auth endpoints at /auth
app.use('/auth', authonice.middleware(User));

// lock down your secret API
app.get('/secret', authonice, function(req, res){
  // you have access to req.user here
  res.send('cool!');
});

// serve up whatever your frontend is
app.use(express.static('./public'));

app.listen(3000);

options

authonice.middleware has a second parameter that looks like this:

{
  // Your secret token key.
  // default: pseudo-random
  secret: 'kittykat0nkeybo04rD',

  // Called when a user registers. Use it to email them.
  // default: console.log, so you can manually verify
  verifyCallback: function(user, code){}
}

If you don't set secret, it will change on every server-reboot, so issued tokens will all be invalid.

HTTPS

PROTIP: Make sure that you use HTTPS, in production, on your auth endpoints, so users aren't sending their credentials plaintext.

Instead of using app.listen(3000) (HTTP) it's highly recommended that you use HTTPS. Here is how you would do that:

var fs = require('fs');
var https = require('https');

var credentials = {
  key: fs.readFileSync('sslcert/server.key', 'utf8'),
  cert: fs.readFileSync('sslcert/server.crt', 'utf8')
};

https.createServer(credentials, app).listen(443);

On PAAS like heroku, often you will get put behind a HTTPS proxy, so your users are safe, but it will serve both HTTP & HTTPS. You can help users to use HTTPS on your whole site, by putting this before all other app stuff:

app.get('*', function(req,res,next){
  if(req.headers['x-forwarded-proto']!='https'){
    res.redirect('https://mypreferreddomain.com'+req.url);
  }else{
    next();
  } 
});

endpoints

If you mounted your endpoint at /auth (above) you will get these REST endpoints:

  • POST /auth/login - login with vars email & password, receive an auth token
  • POST /auth/register - register a new user, send verification email
  • GET /auth/verify/:code - verify a user, based on an email they received
  • POST /auth/resend - resend verification email (requires email in vars)
  • GET /auth/user (LOCKED) - send user object
  • GET /auth/token (LOCKED) - fast token-check, sends OK

All the frontends should support these, once you tell them the endpoint (in the above examples, /auth)

next steps

  • Go get a frontend module to give your app a face.
  • Add some services so you can accept logins authentication from social networks and things.