Feathers Passport
DEPRECATED: This module is deprecated. Please use feathers-authentication instead which provides PassportJS, JSON Web Token and client side authentication support.
feathers-passport adds shared PassportJS authentication for Feathers HTTP REST and websockets services.
Options
feathers-passport will configure the cookieparser, session and Passport middleware for you. The following options are available:
- secret required - The session secret
- store require - A session store to use. Must be provided.
new require('express-session').MemoryStore();
is an option but is not recommended for production. - name (default:
connect.sid
) - The session name (previouskey
) - cookieParser (default:
require('cookie-parser')
) - The cookie parser middleware to use - passport (default:
require('passport')
) - The passport module - createSession (default:
require('express-session')
) - A function that can be called with the options and returns the actual session middleware
You can also pass a function that gets the default values so that you can use them for returning a new configuration. This can be useful to e.g. configure the connect-mongo session store:
var passport = ;var connectMongo = ;var feathersPassport = ; var app = ; app
Example
The following shows a commented example for an application using local authentication with a Feathers user service:
var feathers = ;var passport = ;var crypto = ;var hooks = ;var memory = ;var bodyParser = ;var session = ;var feathersPassport = ;var LocalStrategy = Strategy; // SHA1 hashes a stringvar { var shasum = crypto; shasum; return shasum;}; // A shared session store must be provided.// This MemoryStore is not recommended for productionvar store = ; // Initialize the applicationvar app = // Needed for parsing bodies (login) // Configure feathers-passport // Initialize a user service // A simple Todos service that we can use for testing // Add a login route for the passport login // Host this folder ; var userService = app; // Add a hook to the user service that automatically hashes the// password before saving ituserService; // Use the id to serialize the userpassport; // Deserialize the user retrieving it form the user servicepassport; // Attach the local strategypassport; // Create a user that we can use to log inuserService; app;
Add a login.html
with an HTML form that allows to log our user in:
Username: Password:
Changelog
0.1.0
- Initial release
Author
License
Copyright (c) 2014 David Luecke
Licensed under the MIT license.