-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·58 lines (49 loc) · 1.94 KB
/
index.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
#!/usr/bin/env node
const fs = require('fs')
const express = require('express')
const path = require('path')
require('dotenv').config()
const { configSpcp, configMyInfo } = require('./lib/express')
const PORT = process.env.MOCKPASS_PORT || process.env.PORT || 5156
if (!process.env.SINGPASS_ASSERT_ENDPOINT && !process.env.CORPPASS_ASSERT_ENDPOINT) {
console.warn('SINGPASS_ASSERT_ENDPOINT or CORPPASS_ASSERT_ENDPOINT is not set. ' +
'Value of `PartnerId` request query parameter in redirect URL will be used.'
)
}
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 app = configSpcp(express(), {
serviceProvider,
idpConfig: {
singPass: {
id: process.env.SINGPASS_IDP_ID || 'http://localhost:5156/singpass/saml20',
assertEndpoint: process.env.SINGPASS_ASSERT_ENDPOINT,
},
corpPass: {
id: process.env.CORPPASS_IDP_ID || 'http://localhost:5156/corppass/saml20',
assertEndpoint: process.env.CORPPASS_ASSERT_ENDPOINT,
},
},
showLoginPage: process.env.SHOW_LOGIN_PAGE === 'true',
cryptoConfig,
})
configMyInfo.consent(app)
configMyInfo.v2(app, { serviceProvider })
configMyInfo.v3(app, { serviceProvider })
configMyInfo.biz(app, { serviceProvider })
app.enable('trust proxy')
app.use(express.static(path.join(__dirname, 'public')))
app.listen(
PORT,
err => err
? console.error('Unable to start MockPass', err)
: console.warn(`MockPass listening on ${PORT}`)
)