@opengovsg/mockpass 2.7.8 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,7 +59,7 @@ $ export MOCKPASS_PORT=5156
59
59
  $ export MOCKPASS_NRIC=S8979373D
60
60
  $ export MOCKPASS_UEN=123456789A
61
61
 
62
- $ export SHOW_LOGIN_PAGE=true # Optional, defaults to `false`
62
+ $ export SHOW_LOGIN_PAGE=true # Optional, defaults to `false`; can be overridden per request using `X-Show-Login-Page` HTTP header
63
63
 
64
64
  # Disable signing/encryption (Optional, by default `true`)
65
65
  $ export SIGN_ASSERTION=false
package/index.js CHANGED
@@ -61,7 +61,9 @@ const options = {
61
61
  assertEndpoint: process.env.CORPPASS_ASSERT_ENDPOINT,
62
62
  },
63
63
  },
64
- showLoginPage: process.env.SHOW_LOGIN_PAGE === 'true',
64
+ showLoginPage: (req) => {
65
+ return process.env.SHOW_LOGIN_PAGE === 'true' || req.header('X-Show-Login-Page') === 'true'
66
+ },
65
67
  encryptMyInfo: process.env.ENCRYPT_MYINFO === 'true',
66
68
  cryptoConfig,
67
69
  }
@@ -30,7 +30,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
30
30
  app.get(`/${idp.toLowerCase()}/authorize`, (req, res) => {
31
31
  const redirectURI = req.query.redirect_uri
32
32
  const state = encodeURIComponent(req.query.state)
33
- if (showLoginPage) {
33
+ if (showLoginPage(req)) {
34
34
  const oidc = assertions.oidc[idp]
35
35
  const values = oidc.map((rawId, index) => {
36
36
  const code = encodeURIComponent(
@@ -45,7 +45,7 @@ function config(
45
45
  : idpConfig[idp].assertEndpoint || req.query.PartnerId
46
46
  const relayState = req.query.Target
47
47
  const partnerId = idpConfig[idp].id
48
- if (showLoginPage) {
48
+ if (showLoginPage(req)) {
49
49
  const saml = assertions.saml[idp]
50
50
  const values = saml.map((rawId, index) => {
51
51
  const samlArt = encodeURIComponent(samlArtifact(partnerId, index))
@@ -30,7 +30,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
30
30
  app.get(`${PATH_PREFIX}/authorize`, (req, res) => {
31
31
  const redirectURI = req.query.redirect_uri
32
32
  const state = encodeURIComponent(req.query.state)
33
- if (showLoginPage) {
33
+ if (showLoginPage(req)) {
34
34
  const oidc = assertions.oidc.singPass
35
35
  const values = oidc
36
36
  .filter((rawId) => assertions.myinfo.v3.personas[rawId])
@@ -92,6 +92,9 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
92
92
  nonce,
93
93
  accessToken,
94
94
  )
95
+ // Change sub from `s=${nric},u=${uuid}`
96
+ // to `u=${uuid}` to be consistent with userinfo sub
97
+ idTokenClaims.sub = idTokenClaims.sub.split(',')[1]
95
98
 
96
99
  const signingKey = await jose.JWK.asKey(signingPem, 'pem')
97
100
  const idToken = await jose.JWS.createSign(
@@ -106,7 +109,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
106
109
  refresh_token: refreshToken,
107
110
  expires_in: 24 * 60 * 60,
108
111
  scope: 'openid',
109
- token_type: 'bearer',
112
+ token_type: 'Bearer',
110
113
  id_token: idToken,
111
114
  })
112
115
  } catch (error) {
@@ -129,13 +132,22 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
129
132
  alg: 'A256GCM',
130
133
  })
131
134
 
132
- const encryptedNric = await jose.JWE.createEncrypt(payloadKey)
135
+ const encryptedNric = await jose.JWE.createEncrypt(
136
+ { format: 'compact' },
137
+ payloadKey,
138
+ )
133
139
  .update(nric)
134
140
  .final()
135
- const encryptedName = await jose.JWE.createEncrypt(payloadKey)
141
+ const encryptedName = await jose.JWE.createEncrypt(
142
+ { format: 'compact' },
143
+ payloadKey,
144
+ )
136
145
  .update(name)
137
146
  .final()
138
- const encryptedDateOfBirth = await jose.JWE.createEncrypt(payloadKey)
147
+ const encryptedDateOfBirth = await jose.JWE.createEncrypt(
148
+ { format: 'compact' },
149
+ payloadKey,
150
+ )
139
151
  .update(dateOfBirth)
140
152
  .final()
141
153
  const data = {
@@ -143,11 +155,14 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
143
155
  'myinfo.name': encryptedName,
144
156
  'myinfo.date_of_birth': encryptedDateOfBirth,
145
157
  }
146
- const encryptionKey = await jose.JWK.asKey(serviceProvider.cert, 'pem')
158
+ const encryptionKey = await jose.JWK.asKey(serviceProvider.pubKey, 'pem')
147
159
 
148
160
  const plaintextPayloadKey = JSON.stringify(payloadKey.toJSON(true))
149
161
  console.log(plaintextPayloadKey)
150
- const encryptedPayloadKey = await jose.JWE.createEncrypt(encryptionKey)
162
+ const encryptedPayloadKey = await jose.JWE.createEncrypt(
163
+ { format: 'compact' },
164
+ encryptionKey,
165
+ )
151
166
  .update(plaintextPayloadKey)
152
167
  .final()
153
168
  res.json({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengovsg/mockpass",
3
- "version": "2.7.8",
3
+ "version": "2.8.0",
4
4
  "description": "A mock SingPass/CorpPass server for dev purposes",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -36,10 +36,10 @@
36
36
  "node": ">=8.0.0"
37
37
  },
38
38
  "dependencies": {
39
- "@xmldom/xmldom": "^0.7.2",
39
+ "@xmldom/xmldom": "^0.8.0",
40
40
  "base-64": "^1.0.0",
41
41
  "cookie-parser": "^1.4.3",
42
- "dotenv": "^10.0.0",
42
+ "dotenv": "^16.0.0",
43
43
  "expiry-map": "^1.1.0",
44
44
  "express": "^4.16.3",
45
45
  "jsonwebtoken": "^8.4.0",
@@ -50,20 +50,20 @@
50
50
  "node-jose": "^2.0.0",
51
51
  "uuid": "^8.0.0",
52
52
  "xml-crypto": "^2.1.2",
53
- "xml-encryption": "^1.2.4",
53
+ "xml-encryption": "^2.0.0",
54
54
  "xpath": "0.0.32"
55
55
  },
56
56
  "devDependencies": {
57
- "@commitlint/cli": "^13.1.0",
58
- "@commitlint/config-conventional": "^13.1.0",
59
- "@commitlint/travis-cli": "^13.1.0",
57
+ "@commitlint/cli": "^16.0.1",
58
+ "@commitlint/config-conventional": "^16.0.0",
59
+ "@commitlint/travis-cli": "^16.0.1",
60
60
  "commitizen": "^4.2.4",
61
61
  "cz-conventional-changelog": "^3.2.0",
62
- "eslint": "^7.25.0",
62
+ "eslint": "^8.0.0",
63
63
  "eslint-config-prettier": "^8.3.0",
64
- "eslint-plugin-prettier": "^3.4.0",
64
+ "eslint-plugin-prettier": "^4.0.0",
65
65
  "husky": "^7.0.0",
66
- "lint-staged": "^11.0.0",
66
+ "lint-staged": "^12.0.2",
67
67
  "nodemon": "^2.0.4",
68
68
  "pinst": "^2.1.6",
69
69
  "prettier": "^2.0.5"