Add Authentication to your FeathersJS app.
npm install feathers-authentication@pre --save
This module contains:
feathers-authentication only includes a single hook. This bundled
authenticate hook is used to register an array of one or more authentication strategies on a service method.
Note: Most of the time you should be registering this on your
/authenticationservice. Without it you can hit the
authenticationservice and generate a JWT
accessTokenwithout authentication (ie. anonymous authentication).
The hooks that were once bundled with this module are now located at feathers-legacy-authentication-hooks. They are completely compatible but are deprecated and will not be supported by the core team going forward.
Just like hooks there is an
authenticate middleware. It is used the exact same way you would the regular Passport express middleware.
These other middleware are included and exposed but typically you don't need to worry about them:
exposeCookies- expose cookies to Feathers so they are available to hooks and services
exposeHeaders- expose headers to Feathers so they are available to hooks and services
failureRedirect- support redirecting on auth failure. Only triggered if
successRedirect- support redirecting on auth success. Only triggered if
setCookie- support setting the JWT access token in a cookie. Only enabled if cookies are enabled.
The following default options will be mixed in with your global
auth object from your config file. It will set the mixed options back on to the app so that they are available at any time by calling
app.get('authentication'). They can all be overridden and are depended upon by some of the authentication plugins.
The following plugins are complementary but entirely optional:
Refer to the migration guide.
Here's an example of a Feathers server that uses
feathers-authentication for local auth. You can try it out on your own machine by running the example.
Note: This does NOT implement any authorization. Use feathers-permissions for that.
const feathers = ;const rest = ;const socketio = ;const hooks = ;const memory = ;const bodyParser = ;const errors = ;const errorHandler = ;const local = ;const jwt = ;const auth = ;const app = ;app;app;// Add a hook to the user service that automatically replaces// the password with a hash of the password before saving it.app;const port = 3030;let server = app;server;
You can use the client in the Browser, in NodeJS and in React Native.
;;;;;;const socket = ;const app =// you could use Primus or REST instead;app;
Copyright (c) 2016
Licensed under the MIT license.