Passport strategy for authenticating with Nylas using the OAuth 2.0 protocol API
This module lets you authenticate using Pocket in your Node.js applications. By plugging into Passport. Twitter authentication can be easily and unobstusively integrated into any aplication or framework that supports Express.
$ npm install passport-nylas
The Nylas authentication strategy authenticates users using an email account from mail providers like gmail
, yahoo
, outlook
and more.
The strategy requires a verify
callback, which receives the access token and username as arguments. The verify
callback must call done
providing a user to complete authentication.
In order to identify your application to Nylas, provide a clientID and clientSecret and callbackURI within options. You can obtain your clientID and clientSecret by Creating an Application at Nylas's developers site.
passport.use(new NylasStrategy({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: process.env.callbackURI
},
function(email, accessToken, profile, done) {
User.findOne({nylasId: profile.id}, function(err, user) {
return done(err, user)
});
}
));
Use passport.authenticate()
, specifying the strategy to authenticate requests.
E.g
app.get('/auth/nylas', passport.authenticate('nylas'));
app.get('/auth/nylas/cb/', function(req, res, next) {
passport.authenticate('nylas',
function(err, user, info) {
if (err) {
res.redirect('/login');
}
req.login(user, function(err) {
if (err) {
console.log('Internal Error, Do try again later');
}
res.redirect('/');
})
}
)(req, res, next);
});
Permission can be requested via the scope
option to passport.authenticate()
For example:
app.get('/auth/nylas', passport.authenticate('nylas', {scope: 'email'}));