Passport-Passwordless
This project was build, to handle Passwordless as a build in authentication method using the common authentication library Passport.
By plugging into Passport, Passwordless can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
For now, only the redis store and the email delivery was tested. Feel free to add configuration samples for data stores and code samples for new delivery types.
Installation
$ npm install passport-passwordless
Usage
passport.use(new PasswordlessStrategy({
}, function (req, user, done) {
return done(null, user);
};
Minimal configuration sample
{
allowTokenReuse : true,
tokenLifeTime : 1000 * 60 * 10,
store : {
path : __dirname + '/node_modules/passwordless-redis',
config : [
6379,
'127.0.0.1',
{
}
]
},
delivery : {
type : 'emailjs',
allowGet : true,
path : __dirname + '/node_modules/emailjs',
config : {
server : {
user : 'test.user@domain.com',
password : 'yourPwd',
host : 'yourSmtp',
ssl : true
},
msg : {
text : 'Hello!\nAccess your account here: http://<%= hostname %>?token=<%= tokenToSend %>&uid=',
html : '<html><p>Hello</p><br><p>Access your account here: http://<%= hostname %>?token=<%= tokenToSend %>&uid=<%= uidToSend %></p>'
subject : 'Token for <%= hostname %>'
}
}
}
}
Configuration with description
The path parameter for the store and delivery configuration is needed to exclude obsolete library dependencies of this package. So the delivery / store package can be required from the parent lib.
{
dynamicConfig : false,
userField : 'user',
tokenField : 'tokenField',
uidField : 'uidField',
deliveryField : 'delivery',
originField : null,
allowTokenReuse : true,
tokenLifeTime : 1000 * 60 * 10,
maxTokenLength : 16,
store : {
path : __dirname + '/node_modules/passwordless-redis',
config : [
6379,
'127.0.0.1',
{
}
]
},
delivery : {
type : 'emailjs',
allowGet : true,
path : __dirname + '/node_modules/emailjs',
config : {
server : {
user : 'test.user@domain.com',
password : 'yourPwd',
host : 'yourSmtp',
ssl : true
},
msg : {
text : 'Hello!\nAccess your account here: http://<%= hostname %>?token=<%= tokenToSend %>&uid=',
html : '<html><p>Hello</p><br><p>Access your account here: http://<%= hostname %>?token=<%= tokenToSend %>&uid=<%= uidToSend %></p>'
subject : 'Token for <%= hostname %>'
}
}
},
access : function(user, callback) {
callback(null, user);
}
}
License
The MIT License (MIT)
Copyright © 2016
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.