@depup/express-openid-connect 2.19.4-depup.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/LICENSE +22 -0
- package/README.md +37 -0
- package/changes.json +34 -0
- package/index.d.ts +1055 -0
- package/index.js +9 -0
- package/lib/appSession.js +420 -0
- package/lib/client.js +167 -0
- package/lib/config.js +326 -0
- package/lib/context.js +498 -0
- package/lib/cookies.js +3 -0
- package/lib/crypto.js +119 -0
- package/lib/debug.js +2 -0
- package/lib/hooks/backchannelLogout/isLoggedOut.js +22 -0
- package/lib/hooks/backchannelLogout/onLogIn.js +21 -0
- package/lib/hooks/backchannelLogout/onLogoutToken.js +37 -0
- package/lib/hooks/getLoginState.js +51 -0
- package/lib/once.js +19 -0
- package/lib/transientHandler.js +155 -0
- package/lib/utils/promisifyCompat.js +90 -0
- package/lib/weakCache.js +8 -0
- package/middleware/attemptSilentLogin.js +66 -0
- package/middleware/auth.js +129 -0
- package/middleware/requiresAuth.js +133 -0
- package/middleware/unauthorizedHandler.js +15 -0
- package/package.json +129 -0
package/lib/config.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
const Joi = require('joi');
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const { defaultState: getLoginState } = require('./hooks/getLoginState');
|
|
4
|
+
const isHttps = /^https:/i;
|
|
5
|
+
|
|
6
|
+
const defaultSessionIdGenerator = () => crypto.randomBytes(16).toString('hex');
|
|
7
|
+
|
|
8
|
+
const paramsSchema = Joi.object({
|
|
9
|
+
secret: Joi.alternatives([
|
|
10
|
+
Joi.string().min(8),
|
|
11
|
+
Joi.binary().min(8),
|
|
12
|
+
Joi.array().items(Joi.string().min(8), Joi.binary().min(8)),
|
|
13
|
+
]).required(),
|
|
14
|
+
session: Joi.object({
|
|
15
|
+
rolling: Joi.boolean().optional().default(true),
|
|
16
|
+
rollingDuration: Joi.when(Joi.ref('rolling'), {
|
|
17
|
+
is: true,
|
|
18
|
+
then: Joi.number().integer().messages({
|
|
19
|
+
'number.base':
|
|
20
|
+
'"session.rollingDuration" must be provided an integer value when "session.rolling" is true',
|
|
21
|
+
}),
|
|
22
|
+
otherwise: Joi.boolean().valid(false).messages({
|
|
23
|
+
'any.only':
|
|
24
|
+
'"session.rollingDuration" must be false when "session.rolling" is disabled',
|
|
25
|
+
}),
|
|
26
|
+
})
|
|
27
|
+
.optional()
|
|
28
|
+
.default((parent) => (parent.rolling ? 24 * 60 * 60 : false)), // 1 day when rolling is enabled, else false
|
|
29
|
+
absoluteDuration: Joi.when(Joi.ref('rolling'), {
|
|
30
|
+
is: false,
|
|
31
|
+
then: Joi.number().integer().messages({
|
|
32
|
+
'number.base':
|
|
33
|
+
'"session.absoluteDuration" must be provided an integer value when "session.rolling" is false',
|
|
34
|
+
}),
|
|
35
|
+
otherwise: Joi.alternatives([
|
|
36
|
+
Joi.number().integer(),
|
|
37
|
+
Joi.boolean().valid(false),
|
|
38
|
+
]),
|
|
39
|
+
})
|
|
40
|
+
.optional()
|
|
41
|
+
.default(7 * 24 * 60 * 60), // 7 days,
|
|
42
|
+
name: Joi.string()
|
|
43
|
+
.pattern(/^[0-9a-zA-Z_.-]+$/, { name: 'cookie name' })
|
|
44
|
+
.optional()
|
|
45
|
+
.default('appSession'),
|
|
46
|
+
store: Joi.object()
|
|
47
|
+
.optional()
|
|
48
|
+
.when(Joi.ref('/backchannelLogout'), {
|
|
49
|
+
not: false,
|
|
50
|
+
then: Joi.when('/backchannelLogout.store', {
|
|
51
|
+
not: Joi.exist(),
|
|
52
|
+
then: Joi.when('/backchannelLogout.isLoggedOut', {
|
|
53
|
+
not: Joi.exist(),
|
|
54
|
+
then: Joi.object().required().messages({
|
|
55
|
+
'any.required': `Back-Channel Logout requires a "backchannelLogout.store" (you can also reuse "session.store" if you have stateful sessions) or custom hooks for "isLoggedOut" and "onLogoutToken".`,
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
genid: Joi.function()
|
|
61
|
+
.maxArity(1)
|
|
62
|
+
.optional()
|
|
63
|
+
.default(() => defaultSessionIdGenerator),
|
|
64
|
+
signSessionStoreCookie: Joi.boolean().optional().default(false),
|
|
65
|
+
requireSignedSessionStoreCookie: Joi.boolean()
|
|
66
|
+
.optional()
|
|
67
|
+
.default(Joi.ref('signSessionStoreCookie')),
|
|
68
|
+
cookie: Joi.object({
|
|
69
|
+
domain: Joi.string().optional(),
|
|
70
|
+
transient: Joi.boolean().optional().default(false),
|
|
71
|
+
httpOnly: Joi.boolean().optional().default(true),
|
|
72
|
+
sameSite: Joi.string()
|
|
73
|
+
.valid('Lax', 'Strict', 'None')
|
|
74
|
+
.optional()
|
|
75
|
+
.default('Lax'),
|
|
76
|
+
secure: Joi.when(Joi.ref('/baseURL'), {
|
|
77
|
+
is: Joi.string().pattern(isHttps),
|
|
78
|
+
then: Joi.boolean()
|
|
79
|
+
.default(true)
|
|
80
|
+
.custom((value, { warn }) => {
|
|
81
|
+
if (!value) warn('insecure.cookie');
|
|
82
|
+
return value;
|
|
83
|
+
})
|
|
84
|
+
.messages({
|
|
85
|
+
'insecure.cookie':
|
|
86
|
+
"Setting your cookie to insecure when over https is not recommended, I hope you know what you're doing.",
|
|
87
|
+
}),
|
|
88
|
+
otherwise: Joi.boolean().valid(false).default(false).messages({
|
|
89
|
+
'any.only':
|
|
90
|
+
'Cookies set with the `Secure` property wont be attached to http requests',
|
|
91
|
+
}),
|
|
92
|
+
}),
|
|
93
|
+
path: Joi.string().uri({ relativeOnly: true }).optional(),
|
|
94
|
+
})
|
|
95
|
+
.default()
|
|
96
|
+
.unknown(false),
|
|
97
|
+
})
|
|
98
|
+
.default()
|
|
99
|
+
.unknown(false),
|
|
100
|
+
transactionCookie: Joi.object({
|
|
101
|
+
sameSite: Joi.string()
|
|
102
|
+
.valid('Lax', 'Strict', 'None')
|
|
103
|
+
.optional()
|
|
104
|
+
.default(Joi.ref('...session.cookie.sameSite')),
|
|
105
|
+
name: Joi.string().optional().default('auth_verification'),
|
|
106
|
+
})
|
|
107
|
+
.default()
|
|
108
|
+
.unknown(false),
|
|
109
|
+
auth0Logout: Joi.boolean().optional(),
|
|
110
|
+
tokenEndpointParams: Joi.object().optional(),
|
|
111
|
+
authorizationParams: Joi.object({
|
|
112
|
+
response_type: Joi.string()
|
|
113
|
+
.optional()
|
|
114
|
+
.valid('id_token', 'code id_token', 'code')
|
|
115
|
+
.default('id_token'),
|
|
116
|
+
scope: Joi.string()
|
|
117
|
+
.optional()
|
|
118
|
+
.pattern(/\bopenid\b/, 'contains openid')
|
|
119
|
+
.default('openid profile email'),
|
|
120
|
+
response_mode: Joi.string()
|
|
121
|
+
.optional()
|
|
122
|
+
.when('response_type', {
|
|
123
|
+
is: 'code',
|
|
124
|
+
then: Joi.valid('query', 'form_post'),
|
|
125
|
+
otherwise: Joi.valid('form_post').default('form_post'),
|
|
126
|
+
}),
|
|
127
|
+
})
|
|
128
|
+
.optional()
|
|
129
|
+
.unknown(true)
|
|
130
|
+
.default(),
|
|
131
|
+
logoutParams: Joi.object().optional(),
|
|
132
|
+
backchannelLogout: Joi.alternatives([
|
|
133
|
+
Joi.object({
|
|
134
|
+
store: Joi.object().optional(),
|
|
135
|
+
onLogin: Joi.alternatives([
|
|
136
|
+
Joi.function(),
|
|
137
|
+
Joi.boolean().valid(false),
|
|
138
|
+
]).optional(),
|
|
139
|
+
isLoggedOut: Joi.alternatives([
|
|
140
|
+
Joi.function(),
|
|
141
|
+
Joi.boolean().valid(false),
|
|
142
|
+
]).optional(),
|
|
143
|
+
onLogoutToken: Joi.function().optional(),
|
|
144
|
+
}),
|
|
145
|
+
Joi.boolean(),
|
|
146
|
+
]).default(false),
|
|
147
|
+
baseURL: Joi.string()
|
|
148
|
+
.uri()
|
|
149
|
+
.required()
|
|
150
|
+
.when(Joi.ref('authorizationParams.response_mode'), {
|
|
151
|
+
is: 'form_post',
|
|
152
|
+
then: Joi.string().pattern(isHttps).rule({
|
|
153
|
+
warn: true,
|
|
154
|
+
message: `Using 'form_post' for response_mode may cause issues for you logging in over http, see https://github.com/auth0/express-openid-connect/blob/master/FAQ.md`,
|
|
155
|
+
}),
|
|
156
|
+
}),
|
|
157
|
+
clientID: Joi.string().required(),
|
|
158
|
+
clientSecret: Joi.string()
|
|
159
|
+
.when(
|
|
160
|
+
Joi.ref('clientAuthMethod', {
|
|
161
|
+
adjust: (value) => value && value.includes('client_secret'),
|
|
162
|
+
}),
|
|
163
|
+
{
|
|
164
|
+
is: true,
|
|
165
|
+
then: Joi.string().required().messages({
|
|
166
|
+
'any.required': `"clientSecret" is required for the "clientAuthMethod" "{{clientAuthMethod}}"`,
|
|
167
|
+
}),
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
.when(
|
|
171
|
+
Joi.ref('idTokenSigningAlg', {
|
|
172
|
+
adjust: (value) => value && value.startsWith('HS'),
|
|
173
|
+
}),
|
|
174
|
+
{
|
|
175
|
+
is: true,
|
|
176
|
+
then: Joi.string().required().messages({
|
|
177
|
+
'any.required':
|
|
178
|
+
'"clientSecret" is required for ID tokens with HMAC based algorithms',
|
|
179
|
+
}),
|
|
180
|
+
}
|
|
181
|
+
),
|
|
182
|
+
clockTolerance: Joi.number().optional().default(60),
|
|
183
|
+
enableTelemetry: Joi.boolean().optional().default(true),
|
|
184
|
+
errorOnRequiredAuth: Joi.boolean().optional().default(false),
|
|
185
|
+
attemptSilentLogin: Joi.boolean().optional().default(false),
|
|
186
|
+
getLoginState: Joi.function()
|
|
187
|
+
.optional()
|
|
188
|
+
.default(() => getLoginState),
|
|
189
|
+
afterCallback: Joi.function().optional(),
|
|
190
|
+
identityClaimFilter: Joi.array()
|
|
191
|
+
.optional()
|
|
192
|
+
.default([
|
|
193
|
+
'aud',
|
|
194
|
+
'iss',
|
|
195
|
+
'iat',
|
|
196
|
+
'exp',
|
|
197
|
+
'nbf',
|
|
198
|
+
'nonce',
|
|
199
|
+
'azp',
|
|
200
|
+
'auth_time',
|
|
201
|
+
's_hash',
|
|
202
|
+
'at_hash',
|
|
203
|
+
'c_hash',
|
|
204
|
+
]),
|
|
205
|
+
idpLogout: Joi.boolean()
|
|
206
|
+
.optional()
|
|
207
|
+
.default((parent) => parent.auth0Logout || false),
|
|
208
|
+
idTokenSigningAlg: Joi.string()
|
|
209
|
+
.insensitive()
|
|
210
|
+
.not('none')
|
|
211
|
+
.optional()
|
|
212
|
+
.default('RS256'),
|
|
213
|
+
issuerBaseURL: Joi.string().uri().required(),
|
|
214
|
+
legacySameSiteCookie: Joi.boolean().optional().default(true),
|
|
215
|
+
authRequired: Joi.boolean().optional().default(true),
|
|
216
|
+
pushedAuthorizationRequests: Joi.boolean().optional().default(false),
|
|
217
|
+
routes: Joi.object({
|
|
218
|
+
login: Joi.alternatives([
|
|
219
|
+
Joi.string().uri({ relativeOnly: true }),
|
|
220
|
+
Joi.boolean().valid(false),
|
|
221
|
+
]).default('/login'),
|
|
222
|
+
logout: Joi.alternatives([
|
|
223
|
+
Joi.string().uri({ relativeOnly: true }),
|
|
224
|
+
Joi.boolean().valid(false),
|
|
225
|
+
]).default('/logout'),
|
|
226
|
+
callback: Joi.alternatives([
|
|
227
|
+
Joi.string().uri({ relativeOnly: true }),
|
|
228
|
+
Joi.boolean().valid(false),
|
|
229
|
+
]).default('/callback'),
|
|
230
|
+
postLogoutRedirect: Joi.string().uri({ allowRelative: true }).default(''),
|
|
231
|
+
backchannelLogout: Joi.string()
|
|
232
|
+
.uri({ allowRelative: true })
|
|
233
|
+
.default('/backchannel-logout'),
|
|
234
|
+
})
|
|
235
|
+
.default()
|
|
236
|
+
.unknown(false),
|
|
237
|
+
clientAuthMethod: Joi.string()
|
|
238
|
+
.valid(
|
|
239
|
+
'client_secret_basic',
|
|
240
|
+
'client_secret_post',
|
|
241
|
+
'client_secret_jwt',
|
|
242
|
+
'private_key_jwt',
|
|
243
|
+
'none'
|
|
244
|
+
)
|
|
245
|
+
.optional()
|
|
246
|
+
.default((parent) => {
|
|
247
|
+
if (
|
|
248
|
+
parent.authorizationParams.response_type === 'id_token' &&
|
|
249
|
+
!parent.pushedAuthorizationRequests
|
|
250
|
+
) {
|
|
251
|
+
return 'none';
|
|
252
|
+
}
|
|
253
|
+
if (parent.clientAssertionSigningKey) {
|
|
254
|
+
return 'private_key_jwt';
|
|
255
|
+
}
|
|
256
|
+
return 'client_secret_basic';
|
|
257
|
+
})
|
|
258
|
+
.when(
|
|
259
|
+
Joi.ref('authorizationParams.response_type', {
|
|
260
|
+
adjust: (value) => value && value.includes('code'),
|
|
261
|
+
}),
|
|
262
|
+
{
|
|
263
|
+
is: true,
|
|
264
|
+
then: Joi.string().invalid('none').messages({
|
|
265
|
+
'any.only': 'Public code flow clients are not supported.',
|
|
266
|
+
}),
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
.when(Joi.ref('pushedAuthorizationRequests'), {
|
|
270
|
+
is: true,
|
|
271
|
+
then: Joi.string().invalid('none').messages({
|
|
272
|
+
'any.only': 'Public PAR clients are not supported.',
|
|
273
|
+
}),
|
|
274
|
+
}),
|
|
275
|
+
clientAssertionSigningKey: Joi.any()
|
|
276
|
+
.optional()
|
|
277
|
+
.when(Joi.ref('clientAuthMethod'), {
|
|
278
|
+
is: 'private_key_jwt',
|
|
279
|
+
then: Joi.any().required().messages({
|
|
280
|
+
'any.required':
|
|
281
|
+
'"clientAssertionSigningKey" is required for a "clientAuthMethod" of "private_key_jwt"',
|
|
282
|
+
}),
|
|
283
|
+
}), // <Object> | <string> | <Buffer> | <KeyObject>,
|
|
284
|
+
clientAssertionSigningAlg: Joi.string()
|
|
285
|
+
.valid(
|
|
286
|
+
'RS256',
|
|
287
|
+
'RS384',
|
|
288
|
+
'RS512',
|
|
289
|
+
'PS256',
|
|
290
|
+
'PS384',
|
|
291
|
+
'PS512',
|
|
292
|
+
'ES256',
|
|
293
|
+
'ES256K',
|
|
294
|
+
'ES384',
|
|
295
|
+
'ES512',
|
|
296
|
+
'EdDSA'
|
|
297
|
+
)
|
|
298
|
+
.optional(),
|
|
299
|
+
discoveryCacheMaxAge: Joi.number()
|
|
300
|
+
.optional()
|
|
301
|
+
.min(0)
|
|
302
|
+
.default(10 * 60 * 1000),
|
|
303
|
+
httpTimeout: Joi.number().optional().min(500).default(5000),
|
|
304
|
+
httpUserAgent: Joi.string().optional(),
|
|
305
|
+
httpAgent: Joi.object().optional(),
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
module.exports.get = function (config = {}) {
|
|
309
|
+
config = {
|
|
310
|
+
secret: process.env.SECRET,
|
|
311
|
+
issuerBaseURL: process.env.ISSUER_BASE_URL,
|
|
312
|
+
baseURL: process.env.BASE_URL,
|
|
313
|
+
clientID: process.env.CLIENT_ID,
|
|
314
|
+
clientSecret: process.env.CLIENT_SECRET,
|
|
315
|
+
...config,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const { value, error, warning } = paramsSchema.validate(config);
|
|
319
|
+
if (error) {
|
|
320
|
+
throw new TypeError(error.details[0].message);
|
|
321
|
+
}
|
|
322
|
+
if (warning) {
|
|
323
|
+
console.warn(warning.message);
|
|
324
|
+
}
|
|
325
|
+
return value;
|
|
326
|
+
};
|