forked from opengovsg/mockpass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·62 lines (52 loc) · 1.49 KB
/
app.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
#!/usr/bin/env node
const fs = require('fs')
const express = require('express')
const morgan = require('morgan')
const path = require('path')
require('dotenv').config()
const {
configOIDC,
configOIDCv2,
configMyInfo,
configSGID,
} = require('./lib/express')
const serviceProvider = {
cert: fs.readFileSync(
path.resolve(
__dirname,
process.env.SERVICE_PROVIDER_CERT_PATH || './static/certs/server.crt',
),
),
pubKey: fs.readFileSync(
path.resolve(
__dirname,
process.env.SERVICE_PROVIDER_PUB_KEY || './static/certs/key.pub',
),
),
}
const cryptoConfig = {
signAssertion: process.env.SIGN_ASSERTION !== 'false', // default to true to be backward compatable
signResponse: process.env.SIGN_RESPONSE !== 'false',
encryptAssertion: process.env.ENCRYPT_ASSERTION !== 'false',
resolveArtifactRequestSigned:
process.env.RESOLVE_ARTIFACT_REQUEST_SIGNED !== 'false',
}
const isStateless = process.env.MOCKPASS_STATELESS === 'true'
const options = {
serviceProvider,
showLoginPage: (req) =>
(req.header('X-Show-Login-Page') || process.env.SHOW_LOGIN_PAGE) === 'true',
encryptMyInfo: process.env.ENCRYPT_MYINFO === 'true',
cryptoConfig,
isStateless,
}
const app = express()
app.use(morgan('combined'))
configOIDC(app, options)
configOIDCv2(app, options)
configSGID(app, options)
configMyInfo.consent(app, options)
configMyInfo.v3(app, options)
app.enable('trust proxy')
app.use(express.static(path.join(__dirname, 'public')))
exports.app = app