@whook/oauth2 26.0.0 → 26.0.3

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.
Files changed (85) hide show
  1. package/dist/index.d.ts +6 -2
  2. package/dist/index.js +5 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.test.js +421 -2
  5. package/dist/index.test.js.map +1 -1
  6. package/dist/libs/authorizationRequests.d.ts +6 -0
  7. package/dist/libs/authorizationRequests.js +22 -0
  8. package/dist/libs/authorizationRequests.js.map +1 -0
  9. package/dist/libs/authorizationRequests.test.d.ts +1 -0
  10. package/dist/libs/authorizationRequests.test.js +24 -0
  11. package/dist/libs/authorizationRequests.test.js.map +1 -0
  12. package/dist/libs/errors.d.ts +31 -1
  13. package/dist/libs/errors.js +49 -0
  14. package/dist/libs/errors.js.map +1 -1
  15. package/dist/libs/redirectURI.d.ts +1 -0
  16. package/dist/libs/redirectURI.js +16 -0
  17. package/dist/libs/redirectURI.js.map +1 -1
  18. package/dist/libs/schemas.d.ts +8 -0
  19. package/dist/libs/schemas.js +8 -0
  20. package/dist/libs/schemas.js.map +1 -1
  21. package/dist/libs/verifier.d.ts +3 -0
  22. package/dist/libs/verifier.js +14 -0
  23. package/dist/libs/verifier.js.map +1 -1
  24. package/dist/routes/getOAuth2Authorize.d.ts +30 -14
  25. package/dist/routes/getOAuth2Authorize.js +92 -30
  26. package/dist/routes/getOAuth2Authorize.js.map +1 -1
  27. package/dist/routes/getOAuth2Authorize.test.js +826 -19
  28. package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
  29. package/dist/routes/getOAuth2WellKnownMetadata.d.ts +10 -3
  30. package/dist/routes/getOAuth2WellKnownMetadata.js +30 -5
  31. package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
  32. package/dist/routes/getOAuth2WellKnownMetadata.test.js +20 -18
  33. package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
  34. package/dist/routes/postOAuth2PushedAuthorizationRequest.d.ts +137 -0
  35. package/dist/routes/postOAuth2PushedAuthorizationRequest.js +187 -0
  36. package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -0
  37. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.d.ts +1 -0
  38. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +554 -0
  39. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -0
  40. package/dist/routes/postOAuth2Token.d.ts +12 -0
  41. package/dist/routes/postOAuth2Token.js +12 -0
  42. package/dist/routes/postOAuth2Token.js.map +1 -1
  43. package/dist/services/authCookies.js +8 -4
  44. package/dist/services/authCookies.js.map +1 -1
  45. package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +2 -7
  46. package/dist/services/oAuth2AuthorizationCodeGranter.js +5 -22
  47. package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -1
  48. package/dist/services/oAuth2AuthorizationCodeGranter.test.js +12 -141
  49. package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -1
  50. package/dist/services/oAuth2AuthorizationRequests.d.ts +41 -0
  51. package/dist/services/oAuth2AuthorizationRequests.js +61 -0
  52. package/dist/services/oAuth2AuthorizationRequests.js.map +1 -0
  53. package/dist/services/oAuth2AuthorizationRequests.test.d.ts +1 -0
  54. package/dist/services/oAuth2AuthorizationRequests.test.js +249 -0
  55. package/dist/services/oAuth2AuthorizationRequests.test.js.map +1 -0
  56. package/dist/services/oAuth2Granters.d.ts +10 -12
  57. package/dist/services/oAuth2Granters.js.map +1 -1
  58. package/dist/services/oAuth2ImplicitGranter.js +3 -14
  59. package/dist/services/oAuth2ImplicitGranter.js.map +1 -1
  60. package/dist/services/oAuth2ImplicitGranter.test.js +25 -163
  61. package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -1
  62. package/package.json +7 -6
  63. package/src/index.test.ts +459 -3
  64. package/src/index.ts +17 -0
  65. package/src/libs/authorizationRequests.test.ts +40 -0
  66. package/src/libs/authorizationRequests.ts +42 -0
  67. package/src/libs/errors.ts +87 -1
  68. package/src/libs/redirectURI.ts +22 -0
  69. package/src/libs/schemas.ts +10 -0
  70. package/src/libs/verifier.ts +18 -0
  71. package/src/routes/getOAuth2Authorize.test.ts +940 -23
  72. package/src/routes/getOAuth2Authorize.ts +168 -49
  73. package/src/routes/getOAuth2WellKnownMetadata.test.ts +22 -20
  74. package/src/routes/getOAuth2WellKnownMetadata.ts +44 -8
  75. package/src/routes/postOAuth2PushedAuthorizationRequest.test.ts +681 -0
  76. package/src/routes/postOAuth2PushedAuthorizationRequest.ts +292 -0
  77. package/src/routes/postOAuth2Token.ts +12 -0
  78. package/src/services/authCookies.ts +8 -4
  79. package/src/services/oAuth2AuthorizationCodeGranter.test.ts +12 -169
  80. package/src/services/oAuth2AuthorizationCodeGranter.ts +8 -31
  81. package/src/services/oAuth2AuthorizationRequests.test.ts +282 -0
  82. package/src/services/oAuth2AuthorizationRequests.ts +141 -0
  83. package/src/services/oAuth2Granters.ts +12 -14
  84. package/src/services/oAuth2ImplicitGranter.test.ts +29 -190
  85. package/src/services/oAuth2ImplicitGranter.ts +3 -19
@@ -15,6 +15,9 @@ describe('getOAuth2Authorize', () => {
15
15
  ...OAUTH2_ERRORS_DESCRIPTORS,
16
16
  };
17
17
  const log = jest.fn();
18
+ const oAuth2AuthorizationRequests = {
19
+ check: jest.fn(),
20
+ };
18
21
  const codeGranter = {
19
22
  grantType: 'authorization_code',
20
23
  responseType: 'code',
@@ -30,18 +33,21 @@ describe('getOAuth2Authorize', () => {
30
33
  authorize: jest.fn(),
31
34
  acknowledge: jest.fn(),
32
35
  };
36
+ const readClientGrants = jest.fn();
33
37
  const oAuth2Granters = [
34
38
  codeGranter,
35
39
  tokenGranter,
36
40
  ];
37
41
  beforeEach(() => {
38
- log.mockReset();
39
42
  [
43
+ log,
40
44
  codeGranter.authorize,
41
45
  codeGranter.acknowledge,
42
46
  codeGranter.authenticate,
43
47
  tokenGranter.authorize,
44
48
  tokenGranter.acknowledge,
49
+ readClientGrants,
50
+ oAuth2AuthorizationRequests.check,
45
51
  ].forEach((mock) => mock.mockReset());
46
52
  });
47
53
  test('should redirect', async () => {
@@ -50,26 +56,151 @@ describe('getOAuth2Authorize', () => {
50
56
  codeGranter.authenticate,
51
57
  tokenGranter.authorize,
52
58
  tokenGranter.acknowledge,
59
+ oAuth2AuthorizationRequests.check,
53
60
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
61
+ readClientGrants.mockResolvedValue({
62
+ allowedScopes: ['user', 'admin'],
63
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
64
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
65
+ authenticationData: {
66
+ clientId: 'the_client_app_id',
67
+ scopes: ['user', 'admin'],
68
+ userId: 'user_id',
69
+ },
70
+ isPublicClient: false,
71
+ });
54
72
  codeGranter.authorize.mockResolvedValueOnce({
55
- clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
56
- redirectURI: 'http://lol',
57
73
  scopes: ['user'],
58
74
  });
59
75
  const getOAuth2Authorize = await initGetOAuth2Authorize({
60
76
  OAUTH2,
61
77
  ERRORS_DESCRIPTORS,
62
78
  oAuth2Granters,
79
+ readClientGrants,
80
+ oAuth2AuthorizationRequests,
63
81
  log,
64
82
  });
65
83
  const response = await getOAuth2Authorize({
66
84
  query: {
67
85
  response_type: 'code',
68
- client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
69
- redirect_uri: 'https://www.example.com',
86
+ client_id: 'the_client_app_id',
87
+ redirect_uri: 'https://www.example.com/oauth2/cb',
88
+ scope: 'user',
89
+ state: 'bancal',
90
+ },
91
+ });
92
+ expect({
93
+ response,
94
+ logCalls: log.mock.calls.filter((args) => args[0].endsWith('stack')),
95
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
96
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
97
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
98
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
99
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
100
+ readClientGrantsCalls: readClientGrants.mock.calls,
101
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
102
+ }).toMatchInlineSnapshot(`
103
+ {
104
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
105
+ "codeGranterAuthenticatorAuthenticateCalls": [],
106
+ "codeGranterAuthorizerAuthorizeCalls": [
107
+ [
108
+ {
109
+ "clientGrants": {
110
+ "allowedGrantTypes": [
111
+ "authorization_code",
112
+ "refresh_token",
113
+ ],
114
+ "allowedRedirectURIS": [
115
+ "https://www.example.com/oauth2/cb",
116
+ ],
117
+ "allowedScopes": [
118
+ "user",
119
+ "admin",
120
+ ],
121
+ "authenticationData": {
122
+ "clientId": "the_client_app_id",
123
+ "scopes": [
124
+ "user",
125
+ "admin",
126
+ ],
127
+ "userId": "user_id",
128
+ },
129
+ "isPublicClient": false,
130
+ },
131
+ "clientId": "the_client_app_id",
132
+ "demandedScopes": [
133
+ "user",
134
+ ],
135
+ },
136
+ ],
137
+ ],
138
+ "logCalls": [],
139
+ "oAuth2AuthorizationRequestsCheckCalls": [],
140
+ "readClientGrantsCalls": [
141
+ [
142
+ "the_client_app_id",
143
+ ],
144
+ ],
145
+ "response": {
146
+ "headers": {
147
+ "location": "https://auth.example.com/sign_in?type=code&redirect_uri=https%3A%2F%2Fwww.example.com%2Foauth2%2Fcb&scope=user&client_id=the_client_app_id&state=bancal",
148
+ },
149
+ "status": 302,
150
+ },
151
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
152
+ "tokenGranterAuthorizerAuthorizeCalls": [],
153
+ }
154
+ `);
155
+ });
156
+ test('should redirect with a pushed authorization request URI', async () => {
157
+ [
158
+ codeGranter.acknowledge,
159
+ codeGranter.authenticate,
160
+ tokenGranter.authorize,
161
+ tokenGranter.acknowledge,
162
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
163
+ readClientGrants.mockResolvedValue({
164
+ allowedScopes: ['user', 'admin'],
165
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
166
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
167
+ authenticationData: {
168
+ clientId: 'the_client_app_id',
169
+ scopes: ['user', 'admin'],
170
+ userId: 'user_id',
171
+ },
172
+ isPublicClient: false,
173
+ });
174
+ codeGranter.authorize.mockResolvedValueOnce({
175
+ scopes: ['user'],
176
+ });
177
+ oAuth2AuthorizationRequests.check.mockResolvedValueOnce({
178
+ clientId: 'the_client_app_id',
179
+ parameters: {
180
+ response_type: 'code',
181
+ client_id: 'the_client_app_id',
182
+ redirect_uri: 'https://www.example.com/oauth2/cb',
70
183
  scope: 'user',
71
184
  state: 'bancal',
72
185
  },
186
+ expiresAt: Date.parse('1983-04-28T00:00:00Z'),
187
+ });
188
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
189
+ OAUTH2,
190
+ OAUTH2_PAR: {
191
+ mode: 'enabled',
192
+ },
193
+ ERRORS_DESCRIPTORS,
194
+ oAuth2Granters,
195
+ readClientGrants,
196
+ oAuth2AuthorizationRequests,
197
+ log,
198
+ });
199
+ const response = await getOAuth2Authorize({
200
+ query: {
201
+ client_id: 'the_client_app_id',
202
+ request_uri: 'urn:ietf:params:oauth:request_uri:a_request_ui',
203
+ },
73
204
  });
74
205
  expect({
75
206
  response,
@@ -79,6 +210,8 @@ describe('getOAuth2Authorize', () => {
79
210
  codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
80
211
  tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
81
212
  tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
213
+ readClientGrantsCalls: readClientGrants.mock.calls,
214
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
82
215
  }).toMatchInlineSnapshot(`
83
216
  {
84
217
  "codeGranterAcknowledgerAcknowledgeCalls": [],
@@ -86,19 +219,209 @@ describe('getOAuth2Authorize', () => {
86
219
  "codeGranterAuthorizerAuthorizeCalls": [
87
220
  [
88
221
  {
89
- "clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
90
- "demandedRedirectURI": "https://www.example.com",
222
+ "clientGrants": {
223
+ "allowedGrantTypes": [
224
+ "authorization_code",
225
+ "refresh_token",
226
+ ],
227
+ "allowedRedirectURIS": [
228
+ "https://www.example.com/oauth2/cb",
229
+ ],
230
+ "allowedScopes": [
231
+ "user",
232
+ "admin",
233
+ ],
234
+ "authenticationData": {
235
+ "clientId": "the_client_app_id",
236
+ "scopes": [
237
+ "user",
238
+ "admin",
239
+ ],
240
+ "userId": "user_id",
241
+ },
242
+ "isPublicClient": false,
243
+ },
244
+ "clientId": "the_client_app_id",
91
245
  "demandedScopes": [
92
246
  "user",
93
247
  ],
94
248
  },
95
- {},
96
249
  ],
97
250
  ],
98
251
  "logCalls": [],
252
+ "oAuth2AuthorizationRequestsCheckCalls": [
253
+ [
254
+ "the_client_app_id",
255
+ "urn:ietf:params:oauth:request_uri:a_request_ui",
256
+ ],
257
+ ],
258
+ "readClientGrantsCalls": [
259
+ [
260
+ "the_client_app_id",
261
+ ],
262
+ ],
263
+ "response": {
264
+ "headers": {
265
+ "location": "https://auth.example.com/sign_in?type=code&redirect_uri=https%3A%2F%2Fwww.example.com%2Foauth2%2Fcb&scope=user&client_id=the_client_app_id&state=bancal",
266
+ },
267
+ "status": 302,
268
+ },
269
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
270
+ "tokenGranterAuthorizerAuthorizeCalls": [],
271
+ }
272
+ `);
273
+ });
274
+ test('should reject unknown pushed authorization request URIs', async () => {
275
+ [
276
+ codeGranter.acknowledge,
277
+ codeGranter.authenticate,
278
+ tokenGranter.authorize,
279
+ tokenGranter.acknowledge,
280
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
281
+ readClientGrants.mockResolvedValue({
282
+ allowedScopes: ['user', 'admin'],
283
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
284
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
285
+ authenticationData: {
286
+ clientId: 'the_client_app_id',
287
+ scopes: ['user', 'admin'],
288
+ userId: 'user_id',
289
+ },
290
+ isPublicClient: false,
291
+ });
292
+ codeGranter.authorize.mockResolvedValueOnce({
293
+ scopes: ['user'],
294
+ });
295
+ oAuth2AuthorizationRequests.check.mockResolvedValueOnce(undefined);
296
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
297
+ OAUTH2,
298
+ OAUTH2_PAR: {
299
+ mode: 'enabled',
300
+ },
301
+ ERRORS_DESCRIPTORS,
302
+ oAuth2Granters,
303
+ readClientGrants,
304
+ oAuth2AuthorizationRequests,
305
+ log,
306
+ });
307
+ const response = await getOAuth2Authorize({
308
+ query: {
309
+ client_id: 'the_client_app_id',
310
+ request_uri: 'urn:ietf:params:oauth:request_uri:a_request_ui',
311
+ },
312
+ });
313
+ expect({
314
+ response,
315
+ logCalls: log.mock.calls.filter((args) => !args[0].endsWith('stack')),
316
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
317
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
318
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
319
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
320
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
321
+ readClientGrantsCalls: readClientGrants.mock.calls,
322
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
323
+ }).toMatchInlineSnapshot(`
324
+ {
325
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
326
+ "codeGranterAuthenticatorAuthenticateCalls": [],
327
+ "codeGranterAuthorizerAuthorizeCalls": [],
328
+ "logCalls": [
329
+ [
330
+ "debug",
331
+ "👫 - OAuth2 authorize error.",
332
+ ],
333
+ ],
334
+ "oAuth2AuthorizationRequestsCheckCalls": [
335
+ [
336
+ "the_client_app_id",
337
+ "urn:ietf:params:oauth:request_uri:a_request_ui",
338
+ ],
339
+ ],
340
+ "readClientGrantsCalls": [
341
+ [
342
+ "the_client_app_id",
343
+ ],
344
+ ],
345
+ "response": {
346
+ "headers": {
347
+ "location": "https://www.example.com/oauth2/cb?error=invalid_request_uri&error_description=The+request+URI+is+invalid%2C+expired+or+unknown+%28urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Aa_request_ui%29.",
348
+ },
349
+ "status": 302,
350
+ },
351
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
352
+ "tokenGranterAuthorizerAuthorizeCalls": [],
353
+ }
354
+ `);
355
+ });
356
+ test('should reject pushed authorization request when disabled', async () => {
357
+ [
358
+ codeGranter.acknowledge,
359
+ codeGranter.authenticate,
360
+ tokenGranter.authorize,
361
+ tokenGranter.acknowledge,
362
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
363
+ readClientGrants.mockResolvedValue({
364
+ allowedScopes: ['user', 'admin'],
365
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
366
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
367
+ authenticationData: {
368
+ clientId: 'the_client_app_id',
369
+ scopes: ['user', 'admin'],
370
+ userId: 'user_id',
371
+ },
372
+ isPublicClient: false,
373
+ });
374
+ codeGranter.authorize.mockResolvedValueOnce({
375
+ scopes: ['user'],
376
+ });
377
+ oAuth2AuthorizationRequests.check.mockResolvedValueOnce(undefined);
378
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
379
+ OAUTH2,
380
+ OAUTH2_PAR: {
381
+ mode: 'disabled',
382
+ },
383
+ ERRORS_DESCRIPTORS,
384
+ oAuth2Granters,
385
+ readClientGrants,
386
+ oAuth2AuthorizationRequests,
387
+ log,
388
+ });
389
+ const response = await getOAuth2Authorize({
390
+ query: {
391
+ client_id: 'the_client_app_id',
392
+ request_uri: 'urn:ietf:params:oauth:request_uri:a_request_ui',
393
+ },
394
+ });
395
+ expect({
396
+ response,
397
+ logCalls: log.mock.calls.filter((args) => !args[0].endsWith('stack')),
398
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
399
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
400
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
401
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
402
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
403
+ readClientGrantsCalls: readClientGrants.mock.calls,
404
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
405
+ }).toMatchInlineSnapshot(`
406
+ {
407
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
408
+ "codeGranterAuthenticatorAuthenticateCalls": [],
409
+ "codeGranterAuthorizerAuthorizeCalls": [],
410
+ "logCalls": [
411
+ [
412
+ "debug",
413
+ "👫 - OAuth2 authorize error.",
414
+ ],
415
+ ],
416
+ "oAuth2AuthorizationRequestsCheckCalls": [],
417
+ "readClientGrantsCalls": [
418
+ [
419
+ "the_client_app_id",
420
+ ],
421
+ ],
99
422
  "response": {
100
423
  "headers": {
101
- "location": "https://auth.example.com/sign_in?type=code&redirect_uri=http%3A%2F%2Flol&scope=user&client_id=abbacaca-abba-caca-abba-cacaabbacaca&state=bancal",
424
+ "location": "https://www.example.com/oauth2/cb?error=invalid_request&error_description=Pushed+authorization+requests+are+not+enabled+for+this+server.",
102
425
  },
103
426
  "status": 302,
104
427
  },
@@ -107,7 +430,7 @@ describe('getOAuth2Authorize', () => {
107
430
  }
108
431
  `);
109
432
  });
110
- test('should redirect with an error when some', async () => {
433
+ test('should redirect with an error for bad response type', async () => {
111
434
  [
112
435
  codeGranter.authorize,
113
436
  codeGranter.acknowledge,
@@ -119,13 +442,26 @@ describe('getOAuth2Authorize', () => {
119
442
  OAUTH2,
120
443
  ERRORS_DESCRIPTORS,
121
444
  oAuth2Granters,
445
+ readClientGrants,
446
+ oAuth2AuthorizationRequests,
122
447
  log,
123
448
  });
449
+ readClientGrants.mockResolvedValue({
450
+ allowedScopes: ['user', 'admin'],
451
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
452
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
453
+ authenticationData: {
454
+ clientId: 'the_client_app_id',
455
+ scopes: ['user', 'admin'],
456
+ userId: 'user_id',
457
+ },
458
+ isPublicClient: false,
459
+ });
124
460
  const response = await getOAuth2Authorize({
125
461
  query: {
126
462
  response_type: 'yolo',
127
- client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
128
- redirect_uri: 'https://www.example.com',
463
+ client_id: 'the_client_app_id',
464
+ redirect_uri: 'https://www.example.com/oauth2/cb',
129
465
  scope: 'user',
130
466
  state: 'bancal',
131
467
  },
@@ -138,6 +474,8 @@ describe('getOAuth2Authorize', () => {
138
474
  codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
139
475
  tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
140
476
  tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
477
+ readClientGrantsCalls: readClientGrants.mock.calls,
478
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
141
479
  }).toMatchInlineSnapshot(`
142
480
  {
143
481
  "codeGranterAcknowledgerAcknowledgeCalls": [],
@@ -149,9 +487,15 @@ describe('getOAuth2Authorize', () => {
149
487
  "👫 - OAuth2 authorize error.",
150
488
  ],
151
489
  ],
490
+ "oAuth2AuthorizationRequestsCheckCalls": [],
491
+ "readClientGrantsCalls": [
492
+ [
493
+ "the_client_app_id",
494
+ ],
495
+ ],
152
496
  "response": {
153
497
  "headers": {
154
- "location": "https://www.example.com/?error=unsupported_response_type&error_description=The+response+type+%22yolo%22+is+not+supported.&state=bancal",
498
+ "location": "https://www.example.com/oauth2/cb?error=unsupported_response_type&error_description=The+response+type+%22yolo%22+is+not+supported.&state=bancal",
155
499
  },
156
500
  "status": 302,
157
501
  },
@@ -160,7 +504,7 @@ describe('getOAuth2Authorize', () => {
160
504
  }
161
505
  `);
162
506
  });
163
- test('should redirect with an error with bad scopes', async () => {
507
+ test('should redirect with an error with bad redirect uri', async () => {
164
508
  [
165
509
  codeGranter.authorize,
166
510
  codeGranter.acknowledge,
@@ -168,6 +512,79 @@ describe('getOAuth2Authorize', () => {
168
512
  tokenGranter.authorize,
169
513
  tokenGranter.acknowledge,
170
514
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
515
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
516
+ OAUTH2,
517
+ ERRORS_DESCRIPTORS,
518
+ oAuth2Granters,
519
+ readClientGrants,
520
+ oAuth2AuthorizationRequests,
521
+ log,
522
+ });
523
+ readClientGrants.mockResolvedValue({
524
+ allowedScopes: ['user', 'admin'],
525
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
526
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
527
+ authenticationData: {
528
+ clientId: 'the_client_app_id',
529
+ scopes: ['user', 'admin'],
530
+ userId: 'user_id',
531
+ },
532
+ isPublicClient: false,
533
+ });
534
+ const response = await getOAuth2Authorize({
535
+ query: {
536
+ response_type: 'code',
537
+ client_id: 'the_client_app_id',
538
+ redirect_uri: 'https://www.example.com',
539
+ scope: 'user',
540
+ state: 'bancal',
541
+ },
542
+ });
543
+ expect({
544
+ response,
545
+ logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
546
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
547
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
548
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
549
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
550
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
551
+ readClientGrantsCalls: readClientGrants.mock.calls,
552
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
553
+ }).toMatchInlineSnapshot(`
554
+ {
555
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
556
+ "codeGranterAuthenticatorAuthenticateCalls": [],
557
+ "codeGranterAuthorizerAuthorizeCalls": [],
558
+ "logCalls": [
559
+ [
560
+ "debug",
561
+ "👫 - OAuth2 authorize error.",
562
+ ],
563
+ ],
564
+ "oAuth2AuthorizationRequestsCheckCalls": [],
565
+ "readClientGrantsCalls": [
566
+ [
567
+ "the_client_app_id",
568
+ ],
569
+ ],
570
+ "response": {
571
+ "headers": {
572
+ "location": "https://www.example.com/oauth2/cb?error=invalid_request&error_description=The+client+does+not+accept+that+redirect+URI.&state=bancal",
573
+ },
574
+ "status": 302,
575
+ },
576
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
577
+ "tokenGranterAuthorizerAuthorizeCalls": [],
578
+ }
579
+ `);
580
+ });
581
+ test('should redirect with an error with bad scope and strict scopes', async () => {
582
+ [
583
+ codeGranter.authorize,
584
+ codeGranter.acknowledge,
585
+ codeGranter.authenticate,
586
+ tokenGranter.acknowledge,
587
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
171
588
  const getOAuth2Authorize = await initGetOAuth2Authorize({
172
589
  OAUTH2: {
173
590
  ...OAUTH2,
@@ -175,14 +592,28 @@ describe('getOAuth2Authorize', () => {
175
592
  },
176
593
  ERRORS_DESCRIPTORS,
177
594
  oAuth2Granters,
595
+ readClientGrants,
596
+ oAuth2AuthorizationRequests,
178
597
  log,
179
598
  });
599
+ tokenGranter.authorize.mockResolvedValueOnce({ scopes: ['user'] });
600
+ readClientGrants.mockResolvedValue({
601
+ allowedScopes: ['user'],
602
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
603
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
604
+ authenticationData: {
605
+ clientId: 'the_client_app_id',
606
+ scopes: ['user'],
607
+ userId: 'user_id',
608
+ },
609
+ isPublicClient: false,
610
+ });
180
611
  const response = await getOAuth2Authorize({
181
612
  query: {
182
- response_type: 'code',
183
- client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
184
- redirect_uri: 'https://www.example.com',
185
- scope: 'god',
613
+ response_type: 'token',
614
+ client_id: 'the_client_app_id',
615
+ redirect_uri: 'https://www.example.com/oauth2/cb',
616
+ scope: 'admin',
186
617
  state: 'bancal',
187
618
  },
188
619
  });
@@ -194,6 +625,8 @@ describe('getOAuth2Authorize', () => {
194
625
  codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
195
626
  tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
196
627
  tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
628
+ readClientGrantsCalls: readClientGrants.mock.calls,
629
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
197
630
  }).toMatchInlineSnapshot(`
198
631
  {
199
632
  "codeGranterAcknowledgerAcknowledgeCalls": [],
@@ -205,9 +638,383 @@ describe('getOAuth2Authorize', () => {
205
638
  "👫 - OAuth2 authorize error.",
206
639
  ],
207
640
  ],
641
+ "oAuth2AuthorizationRequestsCheckCalls": [],
642
+ "readClientGrantsCalls": [
643
+ [
644
+ "the_client_app_id",
645
+ ],
646
+ ],
647
+ "response": {
648
+ "headers": {
649
+ "location": "https://www.example.com/oauth2/cb#error=invalid_scope&error_description=This+scope+is+not+supported+%28admin%29.&state=bancal",
650
+ },
651
+ "status": 302,
652
+ },
653
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
654
+ "tokenGranterAuthorizerAuthorizeCalls": [],
655
+ }
656
+ `);
657
+ });
658
+ test('should redirect with an error with bad client', async () => {
659
+ [
660
+ codeGranter.authorize,
661
+ codeGranter.acknowledge,
662
+ codeGranter.authenticate,
663
+ tokenGranter.authorize,
664
+ tokenGranter.acknowledge,
665
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
666
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
667
+ OAUTH2,
668
+ ERRORS_DESCRIPTORS,
669
+ oAuth2Granters,
670
+ readClientGrants,
671
+ oAuth2AuthorizationRequests,
672
+ log,
673
+ });
674
+ readClientGrants.mockRejectedValueOnce(new YError('E_OAUTH2_CLIENT_NOT_FOUND', ['the_client_app_id']));
675
+ const response = await getOAuth2Authorize({
676
+ query: {
677
+ response_type: 'yolo',
678
+ client_id: 'the_client_app_id',
679
+ redirect_uri: 'https://www.example.com/oauth2/cb',
680
+ scope: 'user',
681
+ state: 'bancal',
682
+ },
683
+ });
684
+ expect({
685
+ response,
686
+ logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
687
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
688
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
689
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
690
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
691
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
692
+ readClientGrantsCalls: readClientGrants.mock.calls,
693
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
694
+ }).toMatchInlineSnapshot(`
695
+ {
696
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
697
+ "codeGranterAuthenticatorAuthenticateCalls": [],
698
+ "codeGranterAuthorizerAuthorizeCalls": [],
699
+ "logCalls": [
700
+ [
701
+ "debug",
702
+ "👫 - OAuth2 authorize error.",
703
+ ],
704
+ ],
705
+ "oAuth2AuthorizationRequestsCheckCalls": [],
706
+ "readClientGrantsCalls": [
707
+ [
708
+ "the_client_app_id",
709
+ ],
710
+ ],
711
+ "response": {
712
+ "headers": {
713
+ "location": "https://auth.example.com/sign_in?error=invalid_client&error_description=The+client+provided+does+not+exist+%28the_client_app_id%29.",
714
+ },
715
+ "status": 302,
716
+ },
717
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
718
+ "tokenGranterAuthorizerAuthorizeCalls": [],
719
+ }
720
+ `);
721
+ });
722
+ test('should redirect with an error with bad request uri', async () => {
723
+ [
724
+ codeGranter.authorize,
725
+ codeGranter.acknowledge,
726
+ codeGranter.authenticate,
727
+ tokenGranter.authorize,
728
+ tokenGranter.acknowledge,
729
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
730
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
731
+ OAUTH2,
732
+ OAUTH2_PAR: {
733
+ mode: 'enabled',
734
+ },
735
+ ERRORS_DESCRIPTORS,
736
+ oAuth2Granters,
737
+ readClientGrants,
738
+ oAuth2AuthorizationRequests,
739
+ log,
740
+ });
741
+ readClientGrants.mockResolvedValue({
742
+ allowedScopes: ['user', 'admin'],
743
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
744
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
745
+ authenticationData: {
746
+ clientId: 'the_client_app_id',
747
+ scopes: ['user', 'admin'],
748
+ userId: 'user_id',
749
+ },
750
+ isPublicClient: false,
751
+ });
752
+ const response = await getOAuth2Authorize({
753
+ query: {
754
+ client_id: 'the_client_app_id',
755
+ request_uri: 'not_a_request_uri',
756
+ },
757
+ });
758
+ expect({
759
+ response,
760
+ logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
761
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
762
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
763
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
764
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
765
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
766
+ readClientGrantsCalls: readClientGrants.mock.calls,
767
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
768
+ }).toMatchInlineSnapshot(`
769
+ {
770
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
771
+ "codeGranterAuthenticatorAuthenticateCalls": [],
772
+ "codeGranterAuthorizerAuthorizeCalls": [],
773
+ "logCalls": [
774
+ [
775
+ "debug",
776
+ "👫 - OAuth2 authorize error.",
777
+ ],
778
+ ],
779
+ "oAuth2AuthorizationRequestsCheckCalls": [],
780
+ "readClientGrantsCalls": [
781
+ [
782
+ "the_client_app_id",
783
+ ],
784
+ ],
785
+ "response": {
786
+ "headers": {
787
+ "location": "https://www.example.com/oauth2/cb?error=invalid_request_uri&error_description=The+request+URI+is+invalid%2C+expired+or+unknown+%28not_a_request_uri%29.",
788
+ },
789
+ "status": 302,
790
+ },
791
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
792
+ "tokenGranterAuthorizerAuthorizeCalls": [],
793
+ }
794
+ `);
795
+ });
796
+ test('should redirect with an error with bad request', async () => {
797
+ [
798
+ codeGranter.authorize,
799
+ codeGranter.acknowledge,
800
+ codeGranter.authenticate,
801
+ tokenGranter.authorize,
802
+ tokenGranter.acknowledge,
803
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
804
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
805
+ OAUTH2,
806
+ OAUTH2_PAR: {
807
+ mode: 'enabled',
808
+ },
809
+ ERRORS_DESCRIPTORS,
810
+ oAuth2Granters,
811
+ readClientGrants,
812
+ oAuth2AuthorizationRequests,
813
+ log,
814
+ });
815
+ readClientGrants.mockResolvedValue({
816
+ allowedScopes: ['user', 'admin'],
817
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
818
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
819
+ authenticationData: {
820
+ clientId: 'the_client_app_id',
821
+ scopes: ['user', 'admin'],
822
+ userId: 'user_id',
823
+ },
824
+ isPublicClient: false,
825
+ });
826
+ const response = await getOAuth2Authorize({
827
+ query: {
828
+ client_id: 'the_client_app_id',
829
+ request_uri: 'urn:ietf:params:oauth:request_uri:a_request_ui',
830
+ scope: 'user',
831
+ redirect_uri: 'https://www.example.com/oauth2/cb',
832
+ },
833
+ });
834
+ expect({
835
+ response,
836
+ logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
837
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
838
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
839
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
840
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
841
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
842
+ readClientGrantsCalls: readClientGrants.mock.calls,
843
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
844
+ }).toMatchInlineSnapshot(`
845
+ {
846
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
847
+ "codeGranterAuthenticatorAuthenticateCalls": [],
848
+ "codeGranterAuthorizerAuthorizeCalls": [],
849
+ "logCalls": [
850
+ [
851
+ "debug",
852
+ "👫 - OAuth2 authorize error.",
853
+ ],
854
+ ],
855
+ "oAuth2AuthorizationRequestsCheckCalls": [],
856
+ "readClientGrantsCalls": [
857
+ [
858
+ "the_client_app_id",
859
+ ],
860
+ ],
861
+ "response": {
862
+ "headers": {
863
+ "location": "https://www.example.com/oauth2/cb?error=invalid_request&error_description=The+request+URI+should+not+have+additional+parameters+%28scope%29.",
864
+ },
865
+ "status": 302,
866
+ },
867
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
868
+ "tokenGranterAuthorizerAuthorizeCalls": [],
869
+ }
870
+ `);
871
+ });
872
+ test('should redirect with an error with bad scopes', async () => {
873
+ [
874
+ codeGranter.authorize,
875
+ codeGranter.acknowledge,
876
+ codeGranter.authenticate,
877
+ tokenGranter.authorize,
878
+ tokenGranter.acknowledge,
879
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
880
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
881
+ OAUTH2: {
882
+ ...OAUTH2,
883
+ strictScopesChecks: true,
884
+ },
885
+ ERRORS_DESCRIPTORS,
886
+ oAuth2Granters,
887
+ readClientGrants,
888
+ oAuth2AuthorizationRequests,
889
+ log,
890
+ });
891
+ readClientGrants.mockResolvedValue({
892
+ allowedScopes: ['user', 'admin'],
893
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
894
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
895
+ authenticationData: {
896
+ clientId: 'the_client_app_id',
897
+ scopes: ['user', 'admin'],
898
+ userId: 'user_id',
899
+ },
900
+ isPublicClient: false,
901
+ });
902
+ const response = await getOAuth2Authorize({
903
+ query: {
904
+ response_type: 'code',
905
+ client_id: 'the_client_app_id',
906
+ redirect_uri: 'https://www.example.com/oauth2/cb',
907
+ scope: 'god',
908
+ state: 'bancal',
909
+ },
910
+ });
911
+ expect({
912
+ response,
913
+ logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
914
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
915
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
916
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
917
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
918
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
919
+ readClientGrantsCalls: readClientGrants.mock.calls,
920
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
921
+ }).toMatchInlineSnapshot(`
922
+ {
923
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
924
+ "codeGranterAuthenticatorAuthenticateCalls": [],
925
+ "codeGranterAuthorizerAuthorizeCalls": [],
926
+ "logCalls": [
927
+ [
928
+ "debug",
929
+ "👫 - OAuth2 authorize error.",
930
+ ],
931
+ ],
932
+ "oAuth2AuthorizationRequestsCheckCalls": [],
933
+ "readClientGrantsCalls": [
934
+ [
935
+ "the_client_app_id",
936
+ ],
937
+ ],
938
+ "response": {
939
+ "headers": {
940
+ "location": "https://www.example.com/oauth2/cb?error=invalid_scope&error_description=This+scope+is+not+supported+%28god%29.&state=bancal",
941
+ },
942
+ "status": 302,
943
+ },
944
+ "tokenGranterAcknowledgerAcknowledgeCalls": [],
945
+ "tokenGranterAuthorizerAuthorizeCalls": [],
946
+ }
947
+ `);
948
+ });
949
+ test('should redirect with an error with no PAR when required', async () => {
950
+ [
951
+ codeGranter.authorize,
952
+ codeGranter.acknowledge,
953
+ codeGranter.authenticate,
954
+ tokenGranter.authorize,
955
+ tokenGranter.acknowledge,
956
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
957
+ const getOAuth2Authorize = await initGetOAuth2Authorize({
958
+ OAUTH2,
959
+ OAUTH2_PAR: {
960
+ mode: 'required',
961
+ },
962
+ ERRORS_DESCRIPTORS,
963
+ oAuth2Granters,
964
+ readClientGrants,
965
+ oAuth2AuthorizationRequests,
966
+ log,
967
+ });
968
+ readClientGrants.mockResolvedValue({
969
+ allowedScopes: ['user', 'admin'],
970
+ allowedRedirectURIS: ['https://www.example.com/oauth2/cb'],
971
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
972
+ authenticationData: {
973
+ clientId: 'the_client_app_id',
974
+ scopes: ['user', 'admin'],
975
+ userId: 'user_id',
976
+ },
977
+ isPublicClient: false,
978
+ });
979
+ const response = await getOAuth2Authorize({
980
+ query: {
981
+ response_type: 'code',
982
+ client_id: 'the_client_app_id',
983
+ redirect_uri: 'https://www.example.com/oauth2/cb',
984
+ scope: 'god',
985
+ state: 'bancal',
986
+ },
987
+ });
988
+ expect({
989
+ response,
990
+ logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
991
+ codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
992
+ codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledge.mock.calls,
993
+ codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticate.mock.calls,
994
+ tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
995
+ tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledge.mock.calls,
996
+ readClientGrantsCalls: readClientGrants.mock.calls,
997
+ oAuth2AuthorizationRequestsCheckCalls: oAuth2AuthorizationRequests.check.mock.calls,
998
+ }).toMatchInlineSnapshot(`
999
+ {
1000
+ "codeGranterAcknowledgerAcknowledgeCalls": [],
1001
+ "codeGranterAuthenticatorAuthenticateCalls": [],
1002
+ "codeGranterAuthorizerAuthorizeCalls": [],
1003
+ "logCalls": [
1004
+ [
1005
+ "debug",
1006
+ "👫 - OAuth2 authorize error.",
1007
+ ],
1008
+ ],
1009
+ "oAuth2AuthorizationRequestsCheckCalls": [],
1010
+ "readClientGrantsCalls": [
1011
+ [
1012
+ "the_client_app_id",
1013
+ ],
1014
+ ],
208
1015
  "response": {
209
1016
  "headers": {
210
- "location": "https://www.example.com/?error=invalid_scope&error_description=This+scope+is+not+supported+%28god%29.&state=bancal",
1017
+ "location": "https://www.example.com/oauth2/cb?error=invalid_request&error_description=Pushed+authorization+requests+are+required+for+this+server.",
211
1018
  },
212
1019
  "status": 302,
213
1020
  },