@opengovsg/mockpass 3.0.1 → 3.0.2
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,38 @@ const pki = function pki(authHeader, req, context = {}) {
|
|
|
6
7
|
.split(',')
|
|
7
8
|
.map((v) => v.replace('=', '~').split('~'))
|
|
8
9
|
|
|
9
|
-
const authHeaderFields =
|
|
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 {
|
|
17
|
-
|
|
18
|
-
const {
|
|
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
|
-
'&code=' +
|
|
45
|
-
code +
|
|
46
|
-
'&grant_type=authorization_code' +
|
|
47
|
-
'&nonce=' +
|
|
48
|
-
nonce +
|
|
49
|
-
'&redirect_uri=' +
|
|
50
|
-
redirectURI +
|
|
51
|
-
'&signature_method=RS256' +
|
|
52
|
-
'×tamp=' +
|
|
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
|
-
'×tamp=' +
|
|
68
|
-
timestamp,
|
|
69
|
-
}
|
|
14
|
+
const { method: httpMethod, query } = req
|
|
15
|
+
|
|
16
|
+
const { signature, app_id, nonce, timestamp } = authHeaderFields
|
|
17
|
+
|
|
18
|
+
const params = Object.assign(
|
|
19
|
+
{},
|
|
20
|
+
query,
|
|
21
|
+
{
|
|
22
|
+
nonce,
|
|
23
|
+
app_id,
|
|
24
|
+
signature_method: 'RS256',
|
|
25
|
+
timestamp,
|
|
26
|
+
},
|
|
27
|
+
context.client_secret && context.redirect_uri ? context : {},
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const sortedParams = Object.fromEntries(
|
|
31
|
+
Object.entries(params).sort(([k1], [k2]) => k1.localeCompare(k2)),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const baseString =
|
|
35
|
+
httpMethod.toUpperCase() +
|
|
36
|
+
'&' +
|
|
37
|
+
url +
|
|
38
|
+
'&' +
|
|
39
|
+
qs.unescape(qs.stringify(sortedParams))
|
|
40
|
+
|
|
41
|
+
return { signature, baseString }
|
|
70
42
|
}
|
|
71
43
|
|
|
72
44
|
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,
|
|
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
|
-
|
|
142
|
-
|
|
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.
|
|
3
|
+
"version": "3.0.2",
|
|
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",
|