session-less use of jwt and passport.js
note: by module I mean either a javascript (.js) or coffeescript (.coffee) file
install the following:
- sailsjs
- sails-generate-auth
- passport-jwt
- jwt-simple
- moment
- include jwt in your
config/passport
module - modifiy the
api/services/passport
module to setup jwt. - create a
api/services/protocols/jwt
module - create
api/policies/hasJsonWebToken
module - modify
config/policies
module to use the newhasJsonWebToken
policy, relax policies onUserController.login
but requirehasJsonWebToken
onUserController.index
- create
api.models.ApiToken
module to define valid tokens of various types. - include
api/controllers/UserController
module to expose alogin
action, this generates and returns the users JWT access token.
This does a pretty good job helping you get setup with JWT and Sails:
https://ericswann.wordpress.com/2015/04/24/nozus-js-1-intro-to-sails-with-passport-and-jwt-json-web-token-auth/
I am not the author of that blog, but I did find both of these resources and thought that @eswann did a better job.