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/passportmodule - modifiy the
api/services/passportmodule to setup jwt. - create a
api/services/protocols/jwtmodule - create
api/policies/hasJsonWebTokenmodule - modify
config/policiesmodule to use the newhasJsonWebTokenpolicy, relax policies onUserController.loginbut requirehasJsonWebTokenonUserController.index - create
api.models.ApiTokenmodule to define valid tokens of various types. - include
api/controllers/UserControllermodule to expose aloginaction, 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.