-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefaults.js
1869 lines (1724 loc) · 66.2 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable max-len */
const crypto = require('crypto');
const os = require('os');
const LRU = require('lru-cache');
const attention = require('./attention');
const epochTime = require('./epoch_time');
const cache = new LRU(100);
const warned = new Set();
function shouldChange(name, msg) {
if (!warned.has(name)) {
warned.add(name);
attention.info(`default helper ${name} called, you SHOULD change it in order to ${msg}.`);
}
}
function mustChange(name, msg) {
if (!warned.has(name)) {
warned.add(name);
attention.warn(`default helper ${name} called, you MUST change it in order to ${msg}.`);
}
}
const DEFAULTS = {
/*
* acrValues
*
* description: Array of strings, the Authentication Context Class References that OP supports.
* affects: discovery, ID Token acr claim values
*
* example: FAQ: return acr/amr from session
* To return the acr and/or amr from the established session rather then values from
* a this given authorization request overload the OIDCContext.
*
* ```js
* Object.defineProperties(provider.OIDCContext.prototype, {
* acr: { get() { return this.session.acr; } },
* amr: { get() { return this.session.amr; } },
* });
* ```
*/
acrValues: [],
/*
* claims
*
* description: Array 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, sid: null, auth_time: null, iss: null, openid: ['sub'],
},
/*
* clientCacheDuration
*
* description: A `Number` value (in seconds) describing how long a dynamically loaded client
* should remain cached.
* affects: adapter-backed client cache duration
* recommendation: do not set to a low value or completely disable this, client properties are
* validated upon loading up and this may be potentially an expensive operation, sometimes even
* requesting resources from the network (i.e. client jwks_uri, sector_identifier_uri etc).
*/
clientCacheDuration: Infinity,
/*
* clockTolerance
*
* description: A `Number` value (in seconds) describing the allowed system clock skew
* affects: JWT (ID token, client assertion) and Token expiration validations
* recommendation: Set to a reasonable value (60) to cover server-side client and oidc-provider
* server clock skew
*/
clockTolerance: 0,
/*
* cookies
*
* description: Options for the [cookie module](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
* @nodefault
*/
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 main session reference
interaction: '_grant', // used by the interactions for interaction session reference
resume: '_grant', // used when interactions resume authorization for interaction session reference
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
* recommendation: set cookies.keys and cookies.long.signed = true
*/
long: {
secure: undefined,
signed: undefined,
httpOnly: true, // cookies are not readable by client-side javascript
maxAge: (14 * 24 * 60 * 60) * 1000, // 14 days in ms
},
/*
* cookies.short
*
* description: Options for short-term cookies
* affects: passing of authorization details to interaction
* recommendation: set cookies.keys and cookies.short.signed = true
*/
short: {
secure: undefined,
signed: undefined,
httpOnly: true, // cookies are not readable by client-side javascript
maxAge: (10 * 60) * 1000, // 10 minutes in ms
},
/*
* cookies.keys
*
* description: [Keygrip][keygrip-module] Signing keys used for cookie
* signing to prevent tampering.
* recommendation: Rotate regularly (by prepending new keys) with a reasonable interval and keep
* a reasonable history of keys to allow for returning user session cookies to still be valid
* and re-signed
*/
keys: [],
},
/*
* 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 of strings) to extend the parameters
* recognised by the authorization and device authorization endpoints. These parameters are then
* available in `ctx.oidc.params` as well as passed to interaction session details
* affects: authorization, device_authorization, interaction
*/
extraParams: [],
/*
* features
*
* description: Enable/disable features.
*/
features: {
/*
* features.devInteractions
*
* description: Development-ONLY out of the box interaction views bundled with the library allow
* you to skip the boring frontend part while experimenting with oidc-provider. Enter any
* username (will be used as sub claim value) and any password to proceed.
*
* Be sure to disable and replace this feature with your actual frontend flows and End-User
* authentication flows as soon as possible. These views are not meant to ever be seen by actual
* users.
*/
devInteractions: true,
/*
* features.discovery
*
* title: [Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html)
*
* description: Exposes `/.well-known/webfinger` and `/.well-known/openid-configuration`
* endpoints. Contents of the latter reflect your actual configuration, i.e. available claims,
* features and so on.
*
* WebFinger always returns positive results and links to this issuer, it is not resolving the
* resources in any way.
*/
discovery: true,
/*
* features.requestUri
*
* title: [Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.6.2) - Passing a Request Object by Reference
*
* description: Enables the use and validations of `request_uri` parameter
*
* example: To disable request_uri pre-registration
* Configure `features.requestUri` with an object like so instead of a Boolean value.
*
* ```js
* { requireRequestUriRegistration: false }
* ```
*/
requestUri: true,
/*
* features.oauthNativeApps
*
* title: [RFC8252](https://tools.ietf.org/html/rfc8252) - OAuth 2.0 Native Apps Best Current Practice
* description: Changes `redirect_uris` validations for clients with application_type `native`
* to those defined in the RFC. If PKCE is not enabled it
* will be force-enabled automatically.
*/
oauthNativeApps: true,
/*
* features.pkce
*
* title: [RFC7636](https://tools.ietf.org/html/rfc7636) - Proof Key for Code Exchange by OAuth Public Clients
*
* description: Enables PKCE.
*
*
* example: To force native clients to use PKCE
* Configure `features.pkce` with an object like so instead of a Boolean value.
*
* ```js
* { forcedForNative: true }
* ```
*
* example: To fine-tune the supported code challenge methods
* Configure `features.pkce` with an object like so instead of a Boolean value.
*
* ```js
* { supportedMethods: ['plain', 'S256'] }
* ```
*/
pkce: true,
/*
* features.alwaysIssueRefresh
*
* description: To have your provider issue Refresh Tokens even if offline_access scope is not
* requested.
*
* @skip
*
*/
alwaysIssueRefresh: false,
/*
* features.backchannelLogout
*
* title: [Back-Channel Logout 1.0 - draft 04](https://openid.net/specs/openid-connect-backchannel-1_0-04.html)
*
* description: Enables Back-Channel Logout features.
*
*/
backchannelLogout: false,
/*
* features.certificateBoundAccessTokens
*
* title: [draft-ietf-oauth-mtls-12](https://tools.ietf.org/html/draft-ietf-oauth-mtls-12) - OAuth 2.0 Mutual TLS Client Authentication and Certificate Bound Access Tokens
*
* description: Enables Certificate Bound Access Tokens. Clients may be registered with
* `tls_client_certificate_bound_access_tokens` to indicate intention to receive mutual TLS client
* certificate bound access tokens.
* example: Setting up the environment for Certificate Bound Access Tokens
* To enable Certificate Bound Access Tokens the provider expects your TLS-offloading proxy to
* handle the client certificate validation, parsing, handling, etc. Once set up you are expected
* to forward `x-ssl-client-cert` header with variable values set by this proxy. An important
* aspect is to sanitize the inbound request headers at the proxy.
*
* <br/><br/>
*
* The most common openssl based proxies are Apache and NGINX, with those you're looking to use
*
* <br/><br/>
*
* __`SSLVerifyClient` (Apache) / `ssl_verify_client` (NGINX)__ with the appropriate configuration
* value that matches your setup requirements.
*
* <br/><br/>
*
* Set the proxy request header with variable set as a result of enabling MTLS
*
* ```nginx
* # NGINX
* proxy_set_header x-ssl-client-cert $ssl_client_cert;
* ```
*
* ```apache
* # Apache
* RequestHeader set x-ssl-client-cert ""
* RequestHeader set x-ssl-client-cert "%{SSL_CLIENT_CERT}s"
* ```
*
* You should also consider hosting the endpoints supporting client authentication, on a separate
* host name or port in order to prevent unintended impact on the TLS behaviour of your other
* endpoints, e.g. discovery or the authorization endpoint and changing the discovery values
* for them with a post-middleware.
*
* ```js
* provider.use(async (ctx, next) => {
* await next();
* if (ctx.oidc.route === 'discovery' && ctx.method === 'GET' && ctx.status === 200) {
* ctx.body.userinfo_endpoint = '...';
* ctx.body.token_endpoint = '...';
* }
* });
* ```
*
* When doing that be sure to remove the client
* provided headers of the same name on the non-MTLS enabled host name / port in your proxy setup
* or block the routes for these there completely.
*
*/
certificateBoundAccessTokens: false,
/*
* features.claimsParameter
*
* title: [Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.5) - Requesting Claims using the "claims" Request Parameter
*
* description: Enables the use and validations of `claims` parameter as described in the
* specification.
*
*/
claimsParameter: false,
/*
* features.clientCredentials
*
* title: [RFC6749](https://tools.ietf.org/html/rfc6749#section-1.3.4) - Client Credentials
*
* description: Enables `grant_type=client_credentials` to be used on the token endpoint.
*/
clientCredentials: false,
/*
* features.conformIdTokenClaims
*
* title: ID Token only contains End-User claims when response_type=id_token
*
* description: [Core 1.0 - 5.4. Requesting Claims using Scope Values](https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.4)
* defines that claims requested using the `scope` parameter are only returned from the UserInfo
* Endpoint unless the `response_type` is `id_token`.
*
* The conform/non-conform behaviour results are like so:
*
* | flag value | request params | authorization_endpoint ID Token (if issued) | token_endpoint ID Token (if issued) |
* |---|---|---|---|
* | false | `response_type=` _any_<br/><br/> `scope=openid email` | ✅ `sub`<br/> ✅ `email`<br/> ✅ `email_verified` | ✅ `sub`<br/> ✅ `email`<br/> ✅ `email_verified` |
* | true | `response_type=` _any but_ `id_token`<br/><br/> `scope=openid email` | ✅ `sub`<br/> ❌ `email`<br/> ❌ `email_verified` | ✅ `sub`<br/> ❌ `email`<br/> ❌ `email_verified` |
* | true | `response_type=` _any but_ `id_token`<br/><br/> `scope=openid email`<br/><br/> `claims={"id_token":{"email":null}}` | ✅ `sub`<br/> ✅ `email`<br/> ❌ `email_verified` | ✅ `sub`<br/> ✅ `email`<br/> ❌ `email_verified` |
* | true | `response_type=id_token`<br/><br/> `scope=openid email` | ✅ `sub`<br/> ✅ `email`<br/> ✅ `email_verified` | _n/a_ |
*
* @skip
*
*/
conformIdTokenClaims: true,
/*
* features.deviceFlow
*
* title: [draft-ietf-oauth-device-flow-12](https://tools.ietf.org/html/draft-ietf-oauth-device-flow-12) - Device Flow for Browserless and Input Constrained Devices
*
* description: Enables Device Flow features
*/
deviceFlow: false,
/*
* features.encryption
*
* description: Enables encryption features such as receiving encrypted UserInfo responses,
* encrypted ID Tokens and allow receiving encrypted Request Objects.
*/
encryption: false,
/*
* features.frontchannelLogout
*
* title: [Front-Channel Logout 1.0 - draft 02](https://openid.net/specs/openid-connect-frontchannel-1_0-02.html)
*
* description: Enables Front-Channel Logout features
*/
frontchannelLogout: false,
/*
* features.introspection
*
* title: [RFC7662](https://tools.ietf.org/html/rfc7662) - OAuth 2.0 Token Introspection
*
* description: Enables Token Introspection features
*
*/
introspection: false,
/*
* features.jwtIntrospection
*
* title: [draft-ietf-oauth-jwt-introspection-response-00](https://tools.ietf.org/html/draft-ietf-oauth-jwt-introspection-response-00) - JWT Response for OAuth Token Introspection
*
* description: Enables JWT responses for Token Introspection features
*
*/
jwtIntrospection: false,
/*
* features.jwtResponseModes
*
* title: [openid-financial-api-jarm-wd-01](https://openid.net/specs/openid-financial-api-jarm-wd-01.html) - JWT Secured Authorization Response Mode (JARM)
*
* description: Enables JWT Secured Authorization Responses
*
*/
jwtResponseModes: false,
/*
* features.registration
*
* title: [Dynamic Client Registration 1.0](https://openid.net/specs/openid-connect-registration-1_0.html)
*
* description: Enables Dynamic Client Registration, by default with no Initial Access Token.
*
* example: To enable a fixed Initial Access Token for the registration POST call
* Configure `features.registration` to be an object like so:
*
* ```js
* { initialAccessToken: 'tokenValue' }
* ```
*
* example: To provide your own client_id value generator:
* ```js
* { idFactory: () => randomValue() }
* ```
*
* example: To provide your own client_secret value generator:
* ```js
* { secretFactory: () => randomValue() }
* ```
*
* example: To enable a Initial Access Token lookup from your Adapter's store
* Configure `features.registration` to be an object like so:
*
* ```js
* { initialAccessToken: true }
* ```
*
* example: To add an Initial Access Token and retrive its value
*
* ```js
* new (provider.InitialAccessToken)({}).save().then(console.log);
* ```
*
* example: To define registration and registration management policies
* Policies are sync/async functions that are assigned to an Initial Access Token that run
* before the regular client property validations are run. Multiple policies may be assigned
* to an Initial Access Token and by default the same policies will transfer over to the
* Registration Access Token.
*
* A policy may throw / reject and it may modify the properties object.
*
* To define policy functions configure `features.registration` to be an object like so:
* ```js
* {
* initialAccessToken: true, // to enable adapter-backed initial access tokens
* policies: {
* 'my-policy': function (ctx, properties) {
* // @param ctx - koa request context
* // @param properties - the client properties which are about to be validated
*
* // example of setting a default
* if (!('client_name' in properties)) {
* properties.client_name = generateRandomClientName();
* }
*
* // example of forcing a value
* properties.userinfo_signed_response_alg = 'RS256';
*
* // example of throwing a validation error
* if (someCondition(ctx, properties)) {
* throw new Provider.errors.InvalidClientMetadata('validation error message');
* }
* },
* 'my-policy-2': async function (ctx, properties) {},
* },
* }
* ```
*
* An Initial Access Token with those policies being executed (one by one in that order) is
* created like so
* ```js
* new (provider.InitialAccessToken)({ policies: ['my-policy', 'my-policy-2'] }).save().then(console.log);
* ```
*
* Note: referenced policies must always be present when encountered on a token, an AssertionError
* will be thrown inside the request context if it's not, resulting in a 500 Server Error.
*
* Note: the same policies will be assigned to the Registration Access Token after a successful
* validation. If you wish to assign different policies to the Registration Access Token
* ```js
* // inside your final ran policy
* ctx.oidc.entities.RegistrationAccessToken.policies = ['update-policy'];
* ```
*/
registration: false,
/*
* features.registrationManagement
*
* title: [OAuth 2.0 Dynamic Client Registration Management Protocol](https://tools.ietf.org/html/rfc7592)
*
* description: Enables Update and Delete features described in the RFC, by default with no
* rotating Registration Access Token.
*
* example: To have your provider rotate the Registration Access Token with a successful update
* Configure `features.registrationManagement` as an object like so:
*
* ```js
* { rotateRegistrationAccessToken: true }
* ```
* The provider will discard the current Registration Access Token with a successful update and
* issue a new one, returning it to the client with the Registration Update Response.
*/
registrationManagement: false,
/*
* features.resourceIndicators
*
* title: [draft-ietf-oauth-resource-indicators-01](https://tools.ietf.org/html/draft-ietf-oauth-resource-indicators-01) - Resource Indicators for OAuth 2.0
*
* description: Enables the use of `resource` parameter for the authorization and token
* endpoints. In order for the feature to be any useful you must also use the `audiences`
* helper function to validate the resource(s) and transform it to jwt's token audience.
*
* example: Example use
* This example will
* - throw based on an OP policy when unrecognized or unauthorized resources are requested
* - transform resources to audience and push them down to the audience of access tokens
* - take both, the parameter and previously granted resources into consideration
*
* ```js
* // const { InvalidTarget } = Provider.errors;
* // `resourceAllowedForClient` is the custom OP policy
* // `transform` is mapping the resource values to actual aud values
*
* {
* // ...
* async function audiences(ctx, sub, token, use) {
* if (use === 'access_token') {
* const { oidc: { route, client, params: { resource: resourceParam } } } = ctx;
* let grantedResource;
* if (route === 'token') {
* const { oidc: { params: { grant_type } } } = ctx;
* switch (grant_type) {
* case 'authorization_code':
* grantedResource = ctx.oidc.entities.AuthorizationCode.resource;
* break;
* case 'refresh_token':
* grantedResource = ctx.oidc.entities.RefreshToken.resource;
* break;
* case 'urn:ietf:params:oauth:grant-type:device_code':
* grantedResource = ctx.oidc.entities.DeviceCode.resource;
* break;
* default:
* }
* }
*
* const allowed = await resourceAllowedForClient(resourceParam, grantedResource, client);
* if (!allowed) {
* throw new InvalidResource('unauthorized "resource" requested');
* }
*
* // => array of validated and transformed string audiences or undefined if no audiences
* // are to be listed
* return transform(resourceParam, grantedResource);
* }
* },
* formats: {
* default: 'opaque',
* AccessToken(token) {
* if (Array.isArray(token.aud)) {
* return 'jwt';
* }
*
* return 'opaque';
* }
* },
* // ...
* }
* ```
*/
resourceIndicators: false,
/*
* features.request
*
* title: [Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.6.1) - Passing a Request Object by Value
*
* description: Enables the use and validations of `request` parameter
*/
request: false,
/*
* features.revocation
*
* title: [RFC7009](https://tools.ietf.org/html/rfc7009) - OAuth 2.0 Token Revocation
*
* description: Enables Token Revocation
*
*/
revocation: false,
/*
* features.sessionManagement
*
* title: [Session Management 1.0 - draft 28](https://openid.net/specs/openid-connect-session-1_0-28.html)
*
* description: Enables Session Management features.
*
* example: [RECOMMENDED] To avoid endless "changed" events when Third-Party Cookies are disabled
* The User-Agent must allow access to the provider cookies from a third-party context when the
* OP frame is embedded.
*
* oidc-provider can check if third-party cookie access is enabled using a CDN hosted
* [iframe][third-party-cookies-git]. It is recommended to host these helper pages on your own
* (on a different domain from the one you host oidc-provider on). Once hosted, set the
* `features.sessionManagement.thirdPartyCheckUrl` to an absolute URL for the start page.
* See [this][third-party-cookies-so] for more info.
*
* Note: This is still just a best-effort solution and is in no way bulletproof. Currently there's
* no better way to check if access to third party cookies has been blocked or the cookies are just
* missing. (Safari's ITP 2.0 Storage Access API also cannot be used)
*
* Configure `features.sessionManagement` as an object like so:
*
* ```js
* { thirdPartyCheckUrl: 'https://your-location.example.com/start.html' },
* ```
*
* example: To disable removing frame-ancestors from Content-Security-Policy and X-Frame-Options
* Only do this if you know what you're doing either in a followup middleware or your app server,
* otherwise you shouldn't have the need to touch this option.
*
* Configure `features.sessionManagement` as an object like so:
* ```js
* { keepHeaders: true }
* ```
*/
sessionManagement: false,
/*
* features.webMessageResponseMode
*
* title: [draft-sakimura-oauth-wmrm-00](https://tools.ietf.org/html/draft-sakimura-oauth-wmrm-00) - OAuth 2.0 Web Message Response Mode
*
* description: Enables `web_message` response mode.
*
* Note: Although a general advise to use a `helmet` ([express](https://www.npmjs.com/package/helmet),
* [koa](https://www.npmjs.com/package/koa-helmet)) it is especially advised for your interaction
* views routes if Web Message Response Mode is available on your deployment.
*/
webMessageResponseMode: false,
},
/*
* formats
*
* description: This option allows to configure the token storage and value formats. The different
* values change how a token value is generated as well as what properties get sent to the
* adapter for storage. Multiple formats are defined, see the expected
* [Adapter API](/example/my_adapter.js) for each format's specifics.
* - `opaque` (default) formatted tokens store every property as a root property in your adapter
* - `jwt` formatted tokens are issued as JWTs and stored the same as `opaque` only with
* additional property `jwt`. The signing algorithm for these tokens uses the client's
* `id_token_signed_response_alg` value and falls back to `RS256` for tokens with no relation
* to a client or when the client's alg is `none`
* affects: properties passed to adapters for token types, issued token formats
* recommendation: It is not recommended to set `jwt` as default, if you need it, it's most likely
* just for Access Tokens.
*
* example: To enable JWT Access Tokens
*
* Configure `formats`:
* ```js
* { default: 'opaque', AccessToken: 'jwt' }
* ```
* example: To dynamically decide on the format used, e.g. if it is intended for more audiences
*
* Configure `formats`:
* ```js
* {
* default: 'opaque',
* AccessToken(token) {
* if (Array.isArray(token.aud)) {
* return 'jwt';
* }
*
* return 'opaque';
* }
* }
* ```
*
* example: To enable the legacy format (only recommended for legacy deployments)
* Configure `formats`:
* ```js
* { default: 'legacy' }
* ```
*/
formats: {
default: 'opaque',
AccessToken: undefined,
AuthorizationCode: undefined,
RefreshToken: undefined,
DeviceCode: undefined,
ClientCredentials: undefined,
InitialAccessToken: undefined,
RegistrationAccessToken: undefined,
},
/*
* prompts
*
* description: Array of the prompt values that the OpenID Provider MAY be able to resolve
* affects: authorization
*/
prompts: ['consent', 'login', 'none'],
/*
* responseTypes
*
* description: Array of response_type values that OP supports
* affects: authorization, discovery, registration, registration management
*
* example: Supported values list
* These are values defined in [Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#Authentication)
* and [OAuth 2.0 Multiple Response Type Encoding Practices](https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html)
* ```js
* [
* 'code',
* 'id_token', 'id_token token',
* 'code id_token', 'code token', 'code id_token token',
* 'none',
* ]
* ```
*/
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. Only provide routes starting with "/"
* affects: routing
*/
routes: {
authorization: '/auth',
certificates: '/certs',
check_session: '/session/check',
device_authorization: '/device/auth',
end_session: '/session/end',
introspection: '/token/introspection',
registration: '/reg',
revocation: '/token/revocation',
token: '/token',
userinfo: '/me',
code_verification: '/device',
},
/*
* scopes
*
* description: Array of the scope values that the OP supports
* affects: discovery, authorization, ID Token claims, Userinfo claims
*/
scopes: ['openid', 'offline_access'],
/*
* dynamicScopes
*
* description: Array of the dynamic scope values that the OP supports. These must be regular
* expressions that the OP will check string scope values, that aren't in the static list,
* against.
* affects: discovery, authorization, ID Token claims, Userinfo claims
*
* example: Example: To enable a dynamic scope values like `write:{hex id}` and `read:{hex id}`
* Configure `dynamicScopes` like so:
*
* ```js
* [
* /^write:[a-fA-F0-9]{2,}$/,
* /^read:[a-fA-F0-9]{2,}$/,
* ]
* ```
*/
dynamicScopes: [],
/*
* subjectTypes
*
* description: Array of the Subject Identifier types that this OP supports. Valid types are
* - `public`
* - `pairwise`
* affects: discovery, registration, registration management, ID Token and Userinfo sub claim
* values
*/
subjectTypes: ['public'],
/*
* pairwiseIdentifier
*
* description: Function used by the OP when resolving pairwise ID Token and Userinfo sub claim
* values. See [Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.8.1)
* affects: pairwise ID Token and Userinfo sub claim values
* recommendation: Since this might be called several times in one request with the same arguments
* consider using memoization or otherwise caching the result based on account and client
* ids.
*/
async pairwiseIdentifier(accountId, client) {
mustChange('pairwiseIdentifier', 'provide an implementation for pairwise identifiers, the default one uses `os.hostname()` as salt and is therefore not fit for anything else than development');
return crypto.createHash('sha256')
.update(client.sectorIdentifier)
.update(accountId)
.update(os.hostname()) // put your own unique salt here, or implement other mechanism
.digest('hex');
},
/*
* tokenEndpointAuthMethods
*
* description: Array of Client Authentication methods supported by this OP's Token Endpoint
* affects: discovery, client authentication for token endpoint, registration and
* registration management
* example: Supported values list
* ```js
* [
* 'none',
* 'client_secret_basic', 'client_secret_post',
* 'client_secret_jwt', 'private_key_jwt',
* 'tls_client_auth', 'self_signed_tls_client_auth',
* ]
* ```
* example: Setting up the environment for tls_client_auth and self_signed_tls_client_auth
* To enable MTLS based authentication methods the provider expects your TLS-offloading proxy to
* handle the client certificate validation, parsing, handling, etc. Once set up you are expected
* to forward `x-ssl-client-verify`, `x-ssl-client-s-dn` and `x-ssl-client-cert` headers with
* variable values set by this proxy. An important aspect is to sanitize the inbound request
* headers at the proxy.
*
* <br/><br/>
*
* The most common openssl based proxies are Apache and NGINX, with those you're looking to use
*
* <br/><br/>
*
* __`SSLVerifyClient` (Apache) / `ssl_verify_client` (NGINX)__ with the appropriate configuration
* value that matches your setup requirements.
*
* <br/><br/>
*
* __`SSLCACertificateFile` or `SSLCACertificatePath` (Apache) / `ssl_client_certificate` (NGINX)__
* with the values pointing to your accepted CA Certificates.
*
* <br/><br/>
*
* Set the proxy request headers with variables set as a result of enabling MTLS
*
* ```nginx
* # NGINX
* proxy_set_header x-ssl-client-cert $ssl_client_cert;
* proxy_set_header x-ssl-client-verify $ssl_client_verify;
* proxy_set_header x-ssl-client-s-dn $ssl_client_s_dn;
* ```
*
* ```apache
* # Apache
* RequestHeader set x-ssl-client-cert ""
* RequestHeader set x-ssl-client-cert "%{SSL_CLIENT_CERT}s"
* RequestHeader set x-ssl-client-verify ""
* RequestHeader set x-ssl-client-verify "%{SSL_CLIENT_VERIFY}s"
* RequestHeader set x-ssl-client-s-dn ""
* RequestHeader set x-ssl-client-s-dn "%{SSL_CLIENT_S_DN}s"
* ```
*
* You should also consider hosting the endpoints supporting client authentication, on a separate
* host name or port in order to prevent unintended impact on the TLS behaviour of your other
* endpoints, e.g. discovery or the authorization endpoint and changing the discovery values
* for them with a post-middleware.
*
* ```js
* provider.use(async (ctx, next) => {
* await next();
* if (ctx.oidc.route === 'discovery' && ctx.method === 'GET' && ctx.status === 200) {
* ctx.body.token_endpoint = '...';
* ctx.body.introspection_endpoint = '...';
* ctx.body.revocation_endpoint = '...';
* }
* });
* ```
* When doing that be sure to remove the client
* provided headers of the same name on the non-MTLS enabled host name / port in your proxy setup
* or block the routes for these there completely.
*
*/
tokenEndpointAuthMethods: [
'none',
'client_secret_basic',
'client_secret_jwt',
'client_secret_post',
'private_key_jwt',
],
/*
* ttl
*
* description: Expirations (in seconds, or dynamically returned value) for all token types
* affects: tokens
*
* example: To resolve a ttl on runtime for each new token
* Configure `ttl` for a given token type with a function like so, this must return a value, not a
* Promise.
*
* ```js
* {
* ttl: {
* AccessToken(token, client) {
* // return a Number (in seconds) for the given token (first argument), the associated client is
* // passed as a second argument
* // Tip: if the values are entirely client based memoize the results
* return resolveTTLfor(token, client);
* },
* },
* }
* ```
*/
ttl: {
AccessToken: 60 * 60, // 1 hour in seconds
AuthorizationCode: 10 * 60, // 10 minutes in seconds
ClientCredentials: 10 * 60, // 10 minutes in seconds
DeviceCode: 10 * 60, // 10 minutes in seconds
IdToken: 60 * 60, // 1 hour in seconds
RefreshToken: 14 * 24 * 60 * 60, // 14 days in seconds
},
/*
* extraClientMetadata
*
* description: Allows for custom client metadata to be defined, validated, manipulated as well as
* for existing property validations to be extended
* affects: clients, registration, registration management
* @nodefault
*/
extraClientMetadata: {
/*
* extraClientMetadata.properties
*
* description: Array of property names that clients will be allowed to have defined. Property
* names will have to strictly follow the ones defined here. However, on a Client instance