open5gs/webui/server/routes/auth.js

39 lines
935 B
JavaScript
Raw Normal View History

2017-05-21 14:02:16 +00:00
const express = require('express');
const router = express.Router();
const passport = require('passport');
const jwt = require('jsonwebtoken');
const secret = process.env.JWT_SECRET_KEY || 'change-me';
2017-05-21 14:02:16 +00:00
router.get('/csrf', (req, res) => {
return res.json({csrfToken: res.locals._csrf});
})
router.get('/session', (req, res) => {
let session = {
clientMaxAge: 60000, // 60 seconds
csrfToken: res.locals._csrf
}
if (req.user) {
session.user = req.user
const body = { '_id': req.user._id, 'username': req.user.username, 'roles':req.user.roles };
const token = jwt.sign({ user: body }, secret);
session.authToken = token
2017-05-21 14:02:16 +00:00
}
return res.json(session)
})
router.post('/login',
2017-05-29 08:16:36 +00:00
passport.authenticate('local', { successRedirect: '/' }));
2017-05-21 14:02:16 +00:00
router.post('/logout', (req, res) => {
Squashed commit of the following: commit 5070c19a5469269d036bf243ebdb2740aefc7b8d Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 15:46:35 2022 +0900 updte it commit e49107f46152ff6dce5658b48cfb2c31df61724a Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 11:03:37 2022 +0900 update it commit a55b977e044b1d74ccc8a19f1dbf8194c3cd7daa Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 10:50:41 2022 +0900 update it commit 0ff0930d99bfeb91134271dae0941b4c454d1a3d Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 10:09:35 2022 +0900 update it commit 8cb5038b66d4a605446c6fc200b77f645f7ad328 Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 09:39:08 2022 +0900 update it commit 0a6829dfb6470f3d9b786363d49387fdc688e33b Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 09:06:22 2022 +0900 update it commit ea85035300d9a42cc5f8f7ee300d28cd055f0f1c Author: Sukchan Lee <acetcom@gmail.com> Date: Thu Nov 3 21:36:17 2022 +0900 update it commit e86ba621de332d3f712569cf0580fc8a5321adbd Author: Sukchan Lee <acetcom@gmail.com> Date: Thu Nov 3 17:39:27 2022 +0900 update it commit 2c05df84eabeba7c277c622e5d810768b2895961 Author: Sukchan Lee <acetcom@gmail.com> Date: Thu Nov 3 16:20:47 2022 +0900 update it commit 43c88aed3f2001fdbc28ce0f11cc21dfcdc5906f Author: Sukchan Lee <acetcom@gmail.com> Date: Wed Nov 2 22:17:37 2022 +0900 update it commit b374db4e02e7dd153944f5a6fdc2a50c434dfa09 Author: Sukchan Lee <acetcom@gmail.com> Date: Wed Nov 2 22:05:53 2022 +0900 update it
2022-11-04 08:39:29 +00:00
req.logout(function(err) {
if (err) { return next(err); }
res.redirect('/');
});
2017-05-21 14:02:16 +00:00
});
Squashed commit of the following: commit 5070c19a5469269d036bf243ebdb2740aefc7b8d Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 15:46:35 2022 +0900 updte it commit e49107f46152ff6dce5658b48cfb2c31df61724a Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 11:03:37 2022 +0900 update it commit a55b977e044b1d74ccc8a19f1dbf8194c3cd7daa Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 10:50:41 2022 +0900 update it commit 0ff0930d99bfeb91134271dae0941b4c454d1a3d Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 10:09:35 2022 +0900 update it commit 8cb5038b66d4a605446c6fc200b77f645f7ad328 Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 09:39:08 2022 +0900 update it commit 0a6829dfb6470f3d9b786363d49387fdc688e33b Author: Sukchan Lee <acetcom@gmail.com> Date: Fri Nov 4 09:06:22 2022 +0900 update it commit ea85035300d9a42cc5f8f7ee300d28cd055f0f1c Author: Sukchan Lee <acetcom@gmail.com> Date: Thu Nov 3 21:36:17 2022 +0900 update it commit e86ba621de332d3f712569cf0580fc8a5321adbd Author: Sukchan Lee <acetcom@gmail.com> Date: Thu Nov 3 17:39:27 2022 +0900 update it commit 2c05df84eabeba7c277c622e5d810768b2895961 Author: Sukchan Lee <acetcom@gmail.com> Date: Thu Nov 3 16:20:47 2022 +0900 update it commit 43c88aed3f2001fdbc28ce0f11cc21dfcdc5906f Author: Sukchan Lee <acetcom@gmail.com> Date: Wed Nov 2 22:17:37 2022 +0900 update it commit b374db4e02e7dd153944f5a6fdc2a50c434dfa09 Author: Sukchan Lee <acetcom@gmail.com> Date: Wed Nov 2 22:05:53 2022 +0900 update it
2022-11-04 08:39:29 +00:00
module.exports = router;