@opengovsg/mockpass 3.0.1 → 3.0.3

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.
@@ -1,4 +1,5 @@
1
1
  const _ = require('lodash')
2
+ const qs = require('node:querystring')
2
3
 
3
4
  const pki = function pki(authHeader, req, context = {}) {
4
5
  const authHeaderFieldPairs = _(authHeader)
@@ -6,67 +7,39 @@ const pki = function pki(authHeader, req, context = {}) {
6
7
  .split(',')
7
8
  .map((v) => v.replace('=', '~').split('~'))
8
9
 
9
- const authHeaderFields = _(authHeaderFieldPairs)
10
- .fromPairs()
11
- .mapKeys((_v, k) => _.camelCase(k))
12
- .value()
10
+ const authHeaderFields = Object.fromEntries(authHeaderFieldPairs)
13
11
 
14
12
  const url = `${req.protocol}://${req.get('host')}${req.baseUrl}${req.path}`
15
13
 
16
- const { clientSecret, redirectURI } = context
17
-
18
- const {
19
- method: httpMethod,
20
- query: { attributes, sp_esvcId },
21
- } = req
22
-
23
- const { code } = req.body || {}
24
-
25
- const {
26
- signature,
27
- appId,
28
- appId: clientId,
29
- nonce,
30
- timestamp,
31
- } = authHeaderFields
32
- return {
33
- signature,
34
- baseString: req.path.endsWith('/token')
35
- ? httpMethod.toUpperCase() +
36
- '&' +
37
- url +
38
- '&app_id=' +
39
- appId +
40
- '&client_id=' +
41
- clientId +
42
- '&client_secret=' +
43
- clientSecret +
44
- '&code=' +
45
- code +
46
- '&grant_type=authorization_code' +
47
- '&nonce=' +
48
- nonce +
49
- '&redirect_uri=' +
50
- redirectURI +
51
- '&signature_method=RS256' +
52
- '&timestamp=' +
53
- timestamp
54
- : httpMethod.toUpperCase() +
55
- '&' +
56
- url +
57
- '&app_id=' +
58
- appId +
59
- '&attributes=' +
60
- attributes +
61
- '&client_id=' +
62
- clientId +
63
- '&nonce=' +
64
- nonce +
65
- '&signature_method=RS256' +
66
- (req.path.includes('/person-basic') ? '&sp_esvcId=' + sp_esvcId : '') +
67
- '&timestamp=' +
68
- timestamp,
69
- }
14
+ const { method: httpMethod, query, body } = req
15
+
16
+ const { signature, app_id, nonce, timestamp } = authHeaderFields
17
+
18
+ const params = Object.assign(
19
+ {},
20
+ query,
21
+ body,
22
+ {
23
+ nonce,
24
+ app_id,
25
+ signature_method: 'RS256',
26
+ timestamp,
27
+ },
28
+ context.client_secret && context.redirect_uri ? context : {},
29
+ )
30
+
31
+ const sortedParams = Object.fromEntries(
32
+ Object.entries(params).sort(([k1], [k2]) => k1.localeCompare(k2)),
33
+ )
34
+
35
+ const baseString =
36
+ httpMethod.toUpperCase() +
37
+ '&' +
38
+ url +
39
+ '&' +
40
+ qs.unescape(qs.stringify(sortedParams))
41
+
42
+ return { signature, baseString }
70
43
  }
71
44
 
72
45
  module.exports = { pki }
@@ -132,14 +132,14 @@ module.exports =
132
132
  type: 'application/x-www-form-urlencoded',
133
133
  }),
134
134
  (req, res) => {
135
- const [tokenTemplate, redirectURI] =
135
+ const [tokenTemplate, redirect_uri] =
136
136
  consent.authorizations[req.body.code]
137
137
  const [, authHeader] = (req.get('Authorization') || '').split(' ')
138
138
 
139
139
  const { signature, baseString } = MYINFO_SECRET
140
140
  ? myInfoSignature(authHeader, req, {
141
- clientSecret: MYINFO_SECRET,
142
- redirectURI,
141
+ client_secret: MYINFO_SECRET,
142
+ redirect_uri,
143
143
  })
144
144
  : {}
145
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengovsg/mockpass",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "A mock SingPass/CorpPass server for dev purposes",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -36,7 +36,6 @@
36
36
  "node": ">=8.0.0"
37
37
  },
38
38
  "dependencies": {
39
- "@xmldom/xmldom": "^0.8.0",
40
39
  "base-64": "^1.0.0",
41
40
  "cookie-parser": "^1.4.3",
42
41
  "dotenv": "^16.0.0",