forked from panva/node-oidc-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaults.js
400 lines (346 loc) · 10.8 KB
/
defaults.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
'use strict';
const url = require('url');
const LRU = require('lru-cache');
const epochTime = require('../helpers/epoch_time');
const MemoryAdapter = require('../adapters/memory_adapter');
const cache = new LRU(100);
module.exports = {
/*
* acrValues
*
* description: list of the Authentication Context Class References that OP supports
* affects: discovery, ID Token acr claim values
*/
acrValues: ['0', '1', '2'],
/*
* claims
*
* description: list of the Claim Names of the Claims that the OpenID Provider MAY be able to
* supply values for
* affects: discovery, ID Token claim names, Userinfo claim names
*/
claims: { acr: null, auth_time: null, iss: null, openid: ['sub'] },
/*
* cookies
*
* description: options for https://github.com/pillarjs/cookies#cookiesset-name--value---options--
* used by the OP to keep track of various User-Agent states
* affects: User-Agent sessions, passing of authorization details to interaction
*/
cookies: {
/*
* cookies.names
*
* description: cookie names used by the OP to store and transfer various states
* affects: User-Agent session, Session Management states and interaction cookie names
*/
names: {
session: '_session', // used for session reference
interaction: '_grant', // interaction receives the details for it's path with this cookie
interactionResult: '_grant_result', // interaction results are expected in this cookie
resume: '_grant', // oidc-provider will store the original auth request parameters in this cookie for its resume path
state: '_state', // prefix for sessionManagement state cookies => _state.{clientId}
},
/*
* cookies.long
*
* description: options for long-term cookies
* affects: User-Agent session reference, Session Management states
*/
long: { httpOnly: true, maxAge: (365.25 * 24 * 60 * 60) * 1000 }, // 1 year in ms
/*
* cookies.short
*
* description: options for short-term cookies
* affects: passing of authorization details to interaction
*/
short: { httpOnly: true, maxAge: (60 * 60) * 1000 }, // 60 minutes in ms
},
/*
* discovery
*
* description: pass additional properties to this object to extend the discovery document
* affects: discovery
*/
discovery: {
claim_types_supported: ['normal'],
claims_locales_supported: undefined,
display_values_supported: undefined,
op_policy_uri: undefined,
op_tos_uri: undefined,
service_documentation: undefined,
ui_locales_supported: undefined,
},
/*
* extraParams
*
* description: pass an iterable object (i.e. array or set) to extend the parameters recognized
* by the authorization endpoint. These parameters are then available in ctx.oidc.params as well
* as passed via the _grant cookie to interaction
* affects: authorization, interaction
*/
extraParams: [],
/*
* features
*
* description: enable/disable feature 'packs', see configuration.md for more details
*/
features: {
devInteractions: true,
backchannelLogout: false,
claimsParameter: false,
clientCredentials: false,
discovery: true,
encryption: false,
introspection: false,
alwaysIssueRefresh: false,
registration: false,
registrationManagement: false,
request: false,
requestUri: false,
revocation: false,
oauthNativeApps: false,
sessionManagement: false,
pkce: true,
},
/*
* prompts
*
* description: list of the prompt values that the OpenID Provider MAY be able to resolve
* affects: authorization
*/
prompts: ['consent', 'login', 'none'],
/*
* responseTypes
*
* description: list of the OAuth 2.0 response_type values that OP supports
* affects: authorization, discovery, registration, registration management
*/
responseTypes: [
'code id_token token',
'code id_token',
'code token',
'code',
'id_token token',
'id_token',
'none',
],
/*
* routes
*
* description: routing values used by the OP
* affects: routing
*/
routes: {
authorization: '/auth',
certificates: '/certs',
check_session: '/session/check',
end_session: '/session/end',
introspection: '/token/introspection',
registration: '/reg',
revocation: '/token/revocation',
token: '/token',
userinfo: '/me',
},
/*
* scopes
*
* description: list of the scope values that the OP supports
* affects: discovery, authorization, ID Token claims, Userinfo claims
*/
scopes: ['address', 'email', 'offline_access', 'openid', 'phone', 'profile'],
/*
* subjectTypes
*
* description: list of the Subject Identifier types that this OP supports. Valid types include
* pairwise and public.
* affects: discovery, registration, registration management, ID Token and Userinfo sub claim
* values
*/
subjectTypes: ['public'],
/*
* pairwiseSalt
*
* description: Salt used by OP when resolving pairwise ID Token and Userinfo sub claim value
* affects: ID Token and Userinfo sub claim values
*/
pairwiseSalt: '',
/*
* tokenEndpointAuthMethods
*
* description: list of Client Authentication methods supported by this OP's Token Endpoint
* affects: discovery, client authentication for token, introspection and revocation endpoints,
* registration, registration management
*/
tokenEndpointAuthMethods: [
'none',
'client_secret_basic',
'client_secret_jwt',
'client_secret_post',
'private_key_jwt',
],
/*
* ttl
*
* description: expirations (in seconds) for all token types
* affects: tokens
*/
ttl: {
AccessToken: 2 * 60 * 60, // 2 hours in seconds
AuthorizationCode: 10 * 60, // 10 minutes in seconds
ClientCredentials: 10 * 60, // 10 minutes in seconds
IdToken: 2 * 60 * 60, // 2 hours in seconds
RefreshToken: 30 * 24 * 60 * 60, // 30 days in seconds
},
/*
* postLogoutRedirectUri
*
* description: URL to which the OP redirects the User-Agent when no post_logout_redirect_uri
* is provided by the RP
* affects: session management
*/
postLogoutRedirectUri: '/?loggedOut=true',
/*
* logoutSource
*
* description: HTML source to which a logout form source is passed when session management
* renders a confirmation prompt for the User-Agent.
* affects: session management
*/
logoutSource(form) {
// this => koa context;
this.body = `<!DOCTYPE html>
<head>
<title>Logout</title>
</head>
<body>
${form}
Do you want to logout from OP too?
<button type="submit" form="op.logoutForm" name="logout" value="yes">Yes</button>
<button type="submit" form="op.logoutForm">Please, don't!</button>
</body>
</html>`;
},
/*
* uniqueness
*
* description: function resolving whether a given value with expiration is presented first time
* affects: client_secret_jwt and private_key_jwt client authentications
*/
uniqueness(jti, expiresAt) {
// this => koa context;
if (cache.get(jti)) return Promise.resolve(false);
cache.set(jti, true, (expiresAt - epochTime()) * 1000);
return Promise.resolve(true);
},
/*
* renderError
*
* description: helper used by the OP to present errors which are not meant to be 'forwarded' to
* the RP's redirect_uri
* affects: presentation of errors encountered during authorization
*/
renderError(error) {
// this => koa context;
this.type = 'html';
this.body = `<!DOCTYPE html>
<head>
<title>oops! something went wrong</title>
</head>
<body>
<h1>oops! something went wrong</h1>
<pre>${JSON.stringify(error, null, 4)}</pre>
</body>
</html>`;
},
/*
* interactionUrl
*
* description: helper used by the OP to determine where to redirect User-Agent for necessary
* interaction
* affects: authorization interactions
* note: can return both absolute and relative urls
*/
interactionUrl(interaction) { // eslint-disable-line no-unused-vars
// this => koa context;
try {
return url.parse(this.oidc.urlFor('interaction', { grant: this.oidc.uuid })).pathname;
} catch (err) {
return `/interaction/${this.oidc.uuid}`;
}
},
/*
* interactionCheck
*
* description: helper used by the OP as a final check whether the End-User should be sent to
* interaction or not, the default behavior is that every RP must be authorized per session
* how to: return false if no interaction should be performed
* return an object with relevant error, reason, etc. when interaction should be requested
* affects: authorization interactions
* note: can return a Promise
*/
interactionCheck() {
// this => koa context;
if (!this.oidc.session.sidFor(this.oidc.client.clientId)) {
return {
error: 'consent_required',
error_description: 'client not authorized for End-User session yet',
reason: 'client_not_authorized',
};
}
return false;
},
/*
* findById
*
* description: helper used by the OP to load your account and retrieve it's avaialble claims
* affects: authorization, authorization_code and refresh_token grants, id token claims
* note: The whole method should return a Promise and #claims() can return a Promise too
*/
findById(id) {
// this => koa context;
return Promise.resolve({
accountId: id,
claims() { return { sub: id }; },
});
},
/*
* unsupported
*
* description: fine-tune the algorithms your provider should support by further omitting values
* from the respective discovery properties
* affects: signing, encryption, discovery, client validation
*/
unsupported: {
idTokenEncryptionAlgValues: [],
idTokenEncryptionEncValues: [],
idTokenSigningAlgValues: [],
requestObjectEncryptionAlgValues: [],
requestObjectEncryptionEncValues: [],
requestObjectSigningAlgValues: [],
tokenEndpointAuthSigningAlgValues: [],
userinfoEncryptionAlgValues: [],
userinfoEncryptionEncValues: [],
userinfoSigningAlgValues: [],
},
/*
* adapter
*
* description: TODO
* -> see https://github.com/panva/node-oidc-provider/blob/master/docs/configuration.md#persistance
*/
adapter: MemoryAdapter,
/*
* refreshTokenRotation
*
* description: configures if and how the OP rotates refresh tokens after they are used
* affects: refresh token rotation and adjacent revocation
* supported values:
* 'none' - refresh tokens are not rotated and their initial expiration date is final
* 'rotateAndConsume' - refresh tokens are rotated when used, current token is marked as
* consumed and new one is issued with new TTL, when a consumed refresh
* token is encountered an error is returned instead and the whole token
* chain (grant) is revoked.
*/
refreshTokenRotation: 'none',
};