mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Initial Commit
This commit is contained in:
36
config/auth.js
Normal file
36
config/auth.js
Normal file
@ -0,0 +1,36 @@
|
||||
module.exports = function(app, passport) {
|
||||
app.get('/auth', passport.authenticate('google', {
|
||||
accessType: 'offline',
|
||||
scope: [
|
||||
'https://www.googleapis.com/auth/userinfo.profile',
|
||||
'https://www.googleapis.com/auth/userinfo.email',
|
||||
'https://www.googleapis.com/auth/calendar'
|
||||
]}));
|
||||
|
||||
app.get('/auth/callback', function(req, res, next) {
|
||||
passport.authenticate('google', function(err, user, info) {
|
||||
if (err) { return next(err); }
|
||||
if (!user) { return res.redirect('/login/error'); }
|
||||
|
||||
req.logIn(user, function(err) {
|
||||
if (err) { return next(err); }
|
||||
return res.redirect('/');
|
||||
});
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
return {
|
||||
requiresUiLogin: function(req, res, next) {
|
||||
if (!req.isAuthenticated()) {
|
||||
return res.redirect('/login');
|
||||
}
|
||||
next();
|
||||
},
|
||||
requiresApiAccess: function(req, res, next) {
|
||||
if (!req.isAuthenticated()) {
|
||||
return res.send(403);
|
||||
}
|
||||
next();
|
||||
}
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user