2.0.3 • Published 6 years ago

sails-jwt v2.0.3

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

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 🚗

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.8

6 years ago

1.4.7

7 years ago

1.4.6

7 years ago

1.4.5

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.1

7 years ago

1.4.2

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago