-
Notifications
You must be signed in to change notification settings - Fork 4
/
endpoints.js
39 lines (33 loc) · 1.05 KB
/
endpoints.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module.exports.configureEndpoints = function (app, passport) {
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/login');
}
// root
app.get('/', function (req, res) {
res.render('index', { user: req.user });
});
// accout info - requires authenticated user
app.get('/account', ensureAuthenticated, function (req, res) {
res.render('account', { user: req.user });
});
// login
app.get('/login', function (req, res) {
res.render('login', { user: req.user });
});
// initiates auth sequence with Azure
app.get('/auth/waad', passport.authenticate('oauth2'));
// callback from Azure to complete auth sequence
app.get('/auth/waad/callback', passport.authenticate('oauth2', { failureRedirect: '/login' }),
function (req, res) {
res.redirect('/');
});
// logout
app.get('/logout', function (req, res) {
req.logout();
res.redirect('/');
});
};