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

sails-jwt

v2.0.3

Published

SmartProcure's JWT NPM package.

Downloads

29

Readme

CircleCI

sails-jwt

SmartProcure's JWT NPM package - the best, least-opinionated JWT package for managing users in sailsjs.

Because all other JWT packages are not so good, at best. We're sorry (not really).

DISCLAIMER

This repository is under heavy development. By no means use this in production, unless you know what you're doing.

Dependencies

You must have available: lodash, bluebird, moment and jsonwebtoken.

How to use this

To secure your user model

let { callbackify, cleanRecord, checkPassword } = require('sp-jwt/server').AuthModel()
module.exports = {
  attributes: {
    email: { type: 'string' },
    password: { type: 'string' },
    firstName: { type: 'string' },
    lastName: { type: 'string' },
    verified: { type: 'boolean' },

    group: {
      model: 'groups'
    },

    checkPassword
  },
  afterCreate(values, callback) {
    console.log('afterCreate values', values)
    // TODO: send email here
    callback()
  },
  beforeCreate: callbackify(cleanRecord),
  beforeUpdate: callbackify(cleanRecord)
}

How to use it in your client

Add the authentication to your current transport layer.

let addAuth = require('sp-jwt/client').addAuth
let request = _.curryN(3, addAuth(transport))

Basic auth policy setup

This policy can be used to configure sails.js endpoints to allow support for basic auth authentication through http authorization header in the request

Instantiate and assign in your policies.js configuration

// ... sails policies.js configuration

let basicAuthStatic = require('sails-jwt/server/basicAuthStatic')({
    username: 'defaultUser',
    password: 'defaultPassword',
    BasicAuthController: {
        username: 'controllerUser',
        password: 'controllerPassword'
    },
    BasicAuthMethodController: {
        '*': {
            username: 'controller2User',
            password: 'controller2Password'
        },
        basicAuthMethod: {
            username: 'methodUser',
            password: 'methodPassword'
        },
        openMethod:     true,
        lockedMethod:   false
    }
})

module.exports.policies = {
    // will enforce the default user/pass for all endpoints on this controller
    SomeController: {
        '*': basicAuthStatic
    },
    // will enforce the BasicAuthController user/pass override for all endpoints on this controller
    BasicAuthController: {
        '*': basicAuthStatic
    },
    // will enforce the BasicAuthMethodController "*" user/pass for all endpoints on this controller
    // except the basicAuthMethod which will require the overriding user/pass combo from the configuration for that controller's method
    BasicAuthMethodController: {
        '*': basicAuthStatic
    }
}

License

Too young to get a license 🚗