sails-hook-blacksails
Version:
A Sails Micro-app architecture framework
33 lines (31 loc) • 716 B
JavaScript
/*
* Bearer Authentication Protocol
#
* Bearer Authentication is for authorizing API requests. Once
* a user is created, a token is also generated for that user
* in its passport. This token can be used to authenticate
* API requests.
#
*/
exports.authorize = function authorize(token, done) {
Passport.findOne({
where: {
accessToken: token,
},
}).then((passport) => {
if (!passport) {
return done(null, false);
}
return User.findById(passport.user)
.then((user) => {
if (!user) {
return done(null, false);
}
return done(null, user, {
scope: 'all',
});
});
});
};
// ---
// generated by coffee-script 1.9.2