-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
62 lines (47 loc) · 1.67 KB
/
server.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require('dotenv').config();
const express = require('express');
const path= require("path");
const logger = require('morgan');
const port = process.env.PORT || 3000;
const app = module.exports = express();
app.enable('trust proxy');
app.set('port', port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.use(express.urlencoded({ extended: true }));
app.use('/static', express.static('public'));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(require('express-session')({
secret: process.env.APP_SECRET,
resave: true,
saveUninitialized: false
}));
const { ExpressOIDC } = require('@okta/oidc-middleware');
const oidc = new ExpressOIDC({
issuer: `${process.env.OKTA_ORG_URL}/oauth2/default`,
client_id: process.env.OKTA_CLIENT_ID,
client_secret: process.env.OKTA_CLIENT_SECRET,
redirect_uri: `${process.env.HOST_URL}/authorization-code/callback`,
scope: 'openid profile'
});
app.use(oidc.router);
app.use('/register', require('./routes/register'));
app.get('/logout', (req, res) => {
if(req.userContext) {
const idToken = req.userContext.tokens.id_token;
const to = encodeURI(process.env.HOST_URL);
const params = `id_token_hint=${idToken}&post_logout_redirect_uri=${to}`;
req.logout();
res.redirect(`${process.env.OKTA_ORG_URL}/oauth2/default/v1/logout?${params}`);
} else {
res.redirect('/');
}
});
app.use('/upload', require('./routes/upload'));
app.use('/files', require('./routes/files'));
app.use('/', require('./routes/index'));
app.listen(port, () => {
console.log(`App is live on port ${port}`);
});