@opengovsg/mockpass 3.1.3 → 4.0.1
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 +5 -3
- package/lib/express/sgid.js +44 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,9 +44,11 @@ MyInfo:
|
|
|
44
44
|
- http://localhost:5156/myinfo/v3/person
|
|
45
45
|
|
|
46
46
|
sgID:
|
|
47
|
-
- http://localhost:5156/
|
|
48
|
-
- http://localhost:5156/
|
|
49
|
-
- http://localhost:5156/
|
|
47
|
+
- http://localhost:5156/v2/oauth/authorize
|
|
48
|
+
- http://localhost:5156/v2/oauth/token
|
|
49
|
+
- http://localhost:5156/v2/oauth/userinfo
|
|
50
|
+
- http://localhost:5156/v2/.well-known/openid-configuration - OpenID discovery endpoint
|
|
51
|
+
- http://localhost:5156/v2/.well-known/jwks.json - JWKS endpoint which exposes the auth provider's signing keys
|
|
50
52
|
|
|
51
53
|
Provide your application with the `spcp*` certs found in `static/certs`
|
|
52
54
|
and with application certs at `static/certs/{key.pem|server.crt}`
|
package/lib/express/sgid.js
CHANGED
|
@@ -12,7 +12,9 @@ const LOGIN_TEMPLATE = fs.readFileSync(
|
|
|
12
12
|
'utf8',
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const VERSION_PREFIX = '/v2'
|
|
16
|
+
const OAUTH_PREFIX = '/oauth'
|
|
17
|
+
const PATH_PREFIX = VERSION_PREFIX + OAUTH_PREFIX
|
|
16
18
|
|
|
17
19
|
const signingPem = fs.readFileSync(
|
|
18
20
|
path.resolve(__dirname, '../../static/certs/spcp-key.pem'),
|
|
@@ -77,7 +79,7 @@ function config(app, { showLoginPage, serviceProvider }) {
|
|
|
77
79
|
`Profile ${JSON.stringify(profile)} with token scope ${scopes}`,
|
|
78
80
|
)
|
|
79
81
|
const accessToken = authCode
|
|
80
|
-
const iss = `${req.protocol}://${req.get('host')}`
|
|
82
|
+
const iss = `${req.protocol}://${req.get('host') + VERSION_PREFIX}`
|
|
81
83
|
|
|
82
84
|
const { idTokenClaims, refreshToken } = assertions.oidc.create.singPass(
|
|
83
85
|
profile,
|
|
@@ -149,6 +151,7 @@ function config(app, { showLoginPage, serviceProvider }) {
|
|
|
149
151
|
data[name] = myInfoFields[index]
|
|
150
152
|
})
|
|
151
153
|
data['myinfo.nric_number'] = encryptedNric
|
|
154
|
+
data['openid'] = uuid
|
|
152
155
|
const encryptionKey = await jose.JWK.asKey(serviceProvider.pubKey, 'pem')
|
|
153
156
|
|
|
154
157
|
const plaintextPayloadKey = JSON.stringify(payloadKey.toJSON(true))
|
|
@@ -165,49 +168,52 @@ function config(app, { showLoginPage, serviceProvider }) {
|
|
|
165
168
|
})
|
|
166
169
|
})
|
|
167
170
|
|
|
168
|
-
app.get(
|
|
171
|
+
app.get(`${VERSION_PREFIX}/.well-known/jwks.json`, async (_req, res) => {
|
|
169
172
|
const key = await jose.JWK.asKey(signingPem, 'pem')
|
|
170
173
|
const jwk = key.toJSON()
|
|
171
174
|
jwk.use = 'sig'
|
|
172
175
|
res.json({ keys: [jwk] })
|
|
173
176
|
})
|
|
174
177
|
|
|
175
|
-
app.get(
|
|
176
|
-
|
|
178
|
+
app.get(
|
|
179
|
+
`${VERSION_PREFIX}/.well-known/openid-configuration`,
|
|
180
|
+
async (req, res) => {
|
|
181
|
+
const issuer = `${req.protocol}://${req.get('host') + VERSION_PREFIX}`
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
183
|
+
res.json({
|
|
184
|
+
issuer,
|
|
185
|
+
authorization_endpoint: `${issuer}/${OAUTH_PREFIX}/authorize`,
|
|
186
|
+
token_endpoint: `${issuer}/${OAUTH_PREFIX}/token`,
|
|
187
|
+
userinfo_endpoint: `${issuer}/${OAUTH_PREFIX}/userinfo`,
|
|
188
|
+
jwks_uri: `${issuer}/.well-known/jwks.json`,
|
|
189
|
+
response_types_supported: ['code'],
|
|
190
|
+
grant_types_supported: ['authorization_code'],
|
|
191
|
+
// Note: some of these scopes are not yet officially documented
|
|
192
|
+
// in https://docs.id.gov.sg/data-catalog
|
|
193
|
+
// So they are not officially supported yet.
|
|
194
|
+
scopes_supported: [
|
|
195
|
+
'openid',
|
|
196
|
+
'myinfo.nric_number',
|
|
197
|
+
'myinfo.name',
|
|
198
|
+
'myinfo.email',
|
|
199
|
+
'myinfo.sex',
|
|
200
|
+
'myinfo.race',
|
|
201
|
+
'myinfo.mobile_number',
|
|
202
|
+
'myinfo.registered_address',
|
|
203
|
+
'myinfo.date_of_birth',
|
|
204
|
+
'myinfo.passport_number',
|
|
205
|
+
'myinfo.passport_expiry_date',
|
|
206
|
+
'myinfo.nationality',
|
|
207
|
+
'myinfo.residentialstatus',
|
|
208
|
+
'myinfo.residential',
|
|
209
|
+
'myinfo.housingtype',
|
|
210
|
+
'myinfo.hdbtype',
|
|
211
|
+
],
|
|
212
|
+
id_token_signing_alg_values_supported: ['RS256'],
|
|
213
|
+
subject_types_supported: ['pairwise'],
|
|
214
|
+
})
|
|
215
|
+
},
|
|
216
|
+
)
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
const concatMyInfoRegAddr = (regadd) => {
|