@whook/oauth2 24.1.1 → 25.0.2

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 (64) hide show
  1. package/README.md +12 -10
  2. package/dist/index.d.ts +7 -6
  3. package/dist/index.js +5 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.test.js +173 -168
  6. package/dist/index.test.js.map +1 -1
  7. package/dist/routes/getOAuth2Authorize.d.ts +39 -2
  8. package/dist/routes/getOAuth2Authorize.js +53 -2
  9. package/dist/routes/getOAuth2Authorize.js.map +1 -1
  10. package/dist/routes/getOAuth2WellKnownMetadata.d.ts +239 -0
  11. package/dist/routes/getOAuth2WellKnownMetadata.js +299 -0
  12. package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -0
  13. package/dist/routes/getOAuth2WellKnownMetadata.test.d.ts +1 -0
  14. package/dist/routes/getOAuth2WellKnownMetadata.test.js +100 -0
  15. package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -0
  16. package/dist/routes/postOAuth2Acknowledge.d.ts +1 -1
  17. package/dist/routes/postOAuth2Acknowledge.js +12 -10
  18. package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
  19. package/dist/routes/postOAuth2Acknowledge.test.js +26 -21
  20. package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
  21. package/dist/routes/postOAuth2Token.d.ts +10 -0
  22. package/dist/routes/postOAuth2Token.js +10 -0
  23. package/dist/routes/postOAuth2Token.js.map +1 -1
  24. package/dist/services/authCookies.d.ts +10 -9
  25. package/dist/services/authCookies.js.map +1 -1
  26. package/dist/services/authCookies.test.js.map +1 -1
  27. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +5 -5
  28. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  29. package/dist/services/oAuth2CodeGranter.d.ts +31 -6
  30. package/dist/services/oAuth2CodeGranter.js +37 -9
  31. package/dist/services/oAuth2CodeGranter.js.map +1 -1
  32. package/dist/services/oAuth2CodeGranter.test.js +56 -20
  33. package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
  34. package/dist/services/oAuth2Granters.d.ts +30 -26
  35. package/dist/services/oAuth2Granters.js +14 -0
  36. package/dist/services/oAuth2Granters.js.map +1 -1
  37. package/dist/services/oAuth2PasswordGranter.d.ts +5 -5
  38. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  39. package/dist/services/oAuth2RefreshTokenGranter.d.ts +5 -5
  40. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  41. package/dist/services/oAuth2TokenGranter.d.ts +13 -5
  42. package/dist/services/oAuth2TokenGranter.js +11 -7
  43. package/dist/services/oAuth2TokenGranter.js.map +1 -1
  44. package/package.json +9 -9
  45. package/src/__snapshots__/index.test.ts.snap +3 -0
  46. package/src/index.test.ts +177 -167
  47. package/src/index.ts +34 -2
  48. package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +1 -2
  49. package/src/routes/getOAuth2Authorize.ts +67 -2
  50. package/src/routes/getOAuth2WellKnownMetadata.test.ts +132 -0
  51. package/src/routes/getOAuth2WellKnownMetadata.ts +335 -0
  52. package/src/routes/postOAuth2Acknowledge.test.ts +26 -21
  53. package/src/routes/postOAuth2Acknowledge.ts +19 -18
  54. package/src/routes/postOAuth2Token.ts +12 -1
  55. package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +3 -0
  56. package/src/services/authCookies.test.ts +5 -5
  57. package/src/services/authCookies.ts +13 -9
  58. package/src/services/oAuth2ClientCredentialsGranter.ts +5 -4
  59. package/src/services/oAuth2CodeGranter.test.ts +97 -30
  60. package/src/services/oAuth2CodeGranter.ts +89 -15
  61. package/src/services/oAuth2Granters.ts +60 -64
  62. package/src/services/oAuth2PasswordGranter.ts +5 -4
  63. package/src/services/oAuth2RefreshTokenGranter.ts +5 -4
  64. package/src/services/oAuth2TokenGranter.ts +27 -15
@@ -34,14 +34,18 @@ async function initOAuth2TokenGranter({ checkApplication, oAuth2AccessToken, tim
34
34
  scope: providedScope,
35
35
  }, additionalParameters);
36
36
  return {
37
- // TODO: check a way to avoid this by adding params
38
- ...authenticationData,
39
- applicationId: clientId,
37
+ authenticationData: {
38
+ ...authenticationData,
39
+ applicationId: clientId,
40
+ scope: providedScope,
41
+ },
40
42
  redirectURI: finalRedirectURI,
41
- scope: providedScope,
42
- accessToken,
43
- tokenType: 'bearer',
44
- expiresIn: Math.round((accessTokenExpiresAt - time()) / 1000),
43
+ acknowledgedData: {
44
+ accessToken,
45
+ tokenType: 'bearer',
46
+ expiresIn: Math.round((accessTokenExpiresAt - time()) / 1000),
47
+ },
48
+ additionalParameters,
45
49
  };
46
50
  };
47
51
  log('debug', '👫 - OAuth2TokenGranter Service Initialized!');
@@ -1 +1 @@
1
- {"version":3,"file":"oAuth2TokenGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2TokenGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AASpC,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAgB7C,eAAe,QAAQ,CAAC,WAAW,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE9E,iBAAiB;AACjB,kDAAkD;AAClD,KAAK,UAAU,sBAAsB,CAAC,EACpC,gBAAgB,EAChB,iBAAiB,EACjB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAC1B,GAAG,GAAG,IAAI,GACqB;IAC/B,MAAM,kBAAkB,GAEP,KAAK,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE;QAC1D,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,MAAM,gBAAgB,CAAC;YAC/D,aAAa,EAAE,QAAQ;YACvB,IAAI,EAAE,qBAAqB;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X,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,qBAAqB;SAC5B,CAAC,CAAC;QAEH,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAC3D,MAAM,iBAAiB,CAAC,MAAM,CAC5B,kBAAkB,EAClB;YACE,mDAAmD;YACnD,GAAG,kBAAkB;YACrB,aAAa,EAAE,QAAQ;YACvB,KAAK,EAAE,aAAa;SACrB,EACD,oBAAoB,CACrB,CAAC;QAEJ,OAAO;YACL,kBAAkB,EAAE;gBAClB,GAAG,kBAAkB;gBACrB,aAAa,EAAE,QAAQ;gBACvB,KAAK,EAAE,aAAa;aACrB;YACD,WAAW,EAAE,gBAAgB;YAC7B,gBAAgB,EAAE;gBAChB,WAAW;gBACX,SAAS,EAAE,QAAQ;gBACnB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,oBAAoB,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;aAC9D;YACD,oBAAoB;SACrB,CAAC;IACJ,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,8CAA8C,CAAC,CAAC;IAE7D,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE;YACV,YAAY,EAAE,OAAO;YACrB,SAAS,EAAE,kBAAkB;SAC9B;QACD,YAAY,EAAE;YACZ,kBAAkB,EAAE,OAAO;YAC3B,WAAW,EAAE,oBAAoB;SAClC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  }
24
24
  },
25
25
  "name": "@whook/oauth2",
26
- "version": "24.1.1",
26
+ "version": "25.0.2",
27
27
  "description": "OAuth2 implementation for Whook servers",
28
28
  "type": "module",
29
29
  "publishConfig": {
@@ -46,8 +46,8 @@
46
46
  },
47
47
  "homepage": "https://github.com/nfroidure/whook",
48
48
  "dependencies": {
49
- "@whook/authorization": "^24.1.1",
50
- "@whook/whook": "^24.1.1",
49
+ "@whook/authorization": "^25.0.0",
50
+ "@whook/whook": "^25.0.0",
51
51
  "camelcase": "^9.0.0",
52
52
  "common-services": "^20.0.0",
53
53
  "cookie": "^1.1.1",
@@ -61,22 +61,22 @@
61
61
  "devDependencies": {
62
62
  "@eslint/js": "^10.0.1",
63
63
  "@swc/cli": "^0.8.1",
64
- "@swc/core": "^1.15.30",
64
+ "@swc/core": "^1.15.33",
65
65
  "@swc/jest": "^0.2.39",
66
66
  "axios": "^1.16.0",
67
- "eslint": "^10.2.1",
67
+ "eslint": "^10.4.0",
68
68
  "eslint-config-prettier": "^10.1.8",
69
69
  "eslint-plugin-jest": "^29.15.2",
70
70
  "eslint-plugin-prettier": "^5.5.5",
71
71
  "http-auth-utils": "^7.0.1",
72
- "jest": "^30.3.0",
72
+ "jest": "^30.4.2",
73
73
  "jsdoc-to-markdown": "^9.1.3",
74
74
  "metapak": "^7.1.1",
75
- "metapak-nfroidure": "22.1.2",
75
+ "metapak-nfroidure": "22.1.3",
76
76
  "prettier": "^3.8.3",
77
77
  "rimraf": "^6.1.3",
78
78
  "typescript": "^6.0.3",
79
- "typescript-eslint": "^8.59.0"
79
+ "typescript-eslint": "^8.59.3"
80
80
  },
81
81
  "contributors": [],
82
82
  "engines": {
@@ -135,7 +135,7 @@
135
135
  "rebuild": "swc ./src -s -d dist -C jsc.target=es2022",
136
136
  "test": "node --run jest"
137
137
  },
138
- "gitHead": "21fa0fb3bbffa9f5be14c1dcde7c3f527e2b54ec",
138
+ "gitHead": "86dc20af6818a0d8535b69642e6622bc4bda9d15",
139
139
  "funding": {
140
140
  "type": "individual",
141
141
  "url": "https://github.com/sponsors/nfroidure"
@@ -126,6 +126,7 @@ exports[`OAuth2 server with the code flow should produce new tokens 2`] = `
126
126
  },
127
127
  "a_grant_code",
128
128
  "http://redirect.example.com/yolo",
129
+ undefined,
129
130
  ],
130
131
  ],
131
132
  "oAuth2CodeCreateCalls": [],
@@ -179,6 +180,8 @@ exports[`OAuth2 server with the code flow should redirect with a code 2`] = `
179
180
  "userId": "2",
180
181
  },
181
182
  "http://redirect.example.com/yolo?a_param=a_value",
183
+ undefined,
184
+ undefined,
182
185
  {},
183
186
  ],
184
187
  ],
package/src/index.test.ts CHANGED
@@ -35,9 +35,14 @@ import {
35
35
  getOAuth2AuthorizeRedirectURIParameter,
36
36
  getOAuth2AuthorizeScopeParameter,
37
37
  getOAuth2AuthorizeStateParameter,
38
+ getOAuth2AuthorizeCodeChallengeSchema,
39
+ getOAuth2AuthorizeCodeChallengeParameter,
40
+ getOAuth2AuthorizeCodeChallengeMethodSchema,
41
+ getOAuth2AuthorizeCodeChallengeMethodParameter,
38
42
  initPostOAuth2Acknowledge,
39
43
  postOAuth2AcknowledgeDefinition,
40
44
  initPostOAuth2Token,
45
+ postOAuth2TokenCodeVerifierSchema,
41
46
  postOAuth2TokenDefinition,
42
47
  OAUTH2_ERRORS_DESCRIPTORS,
43
48
  initOAuth2CodeGranter,
@@ -127,6 +132,8 @@ describe('OAuth2 server', () => {
127
132
  getOAuth2AuthorizeRedirectURIParameter,
128
133
  getOAuth2AuthorizeScopeParameter,
129
134
  getOAuth2AuthorizeStateParameter,
135
+ getOAuth2AuthorizeCodeChallengeParameter,
136
+ getOAuth2AuthorizeCodeChallengeMethodParameter,
130
137
  ].reduce(
131
138
  (parametersHash, { name, parameter }) => ({
132
139
  ...parametersHash,
@@ -140,6 +147,9 @@ describe('OAuth2 server', () => {
140
147
  postOAuth2TokenClientCredentialsTokenRequestBodySchema,
141
148
  postOAuth2TokenRefreshTokenRequestBodySchema,
142
149
  postOAuth2TokenTokenBodySchema,
150
+ getOAuth2AuthorizeCodeChallengeSchema,
151
+ getOAuth2AuthorizeCodeChallengeMethodSchema,
152
+ postOAuth2TokenCodeVerifierSchema,
143
153
  ].reduce(
144
154
  (schemasHash, { name, schema }) => ({
145
155
  ...schemasHash,
@@ -353,31 +363,31 @@ describe('OAuth2 server', () => {
353
363
  },
354
364
  data,
355
365
  }).toMatchInlineSnapshot(`
356
- {
357
- "data": {
358
- "access_token": "an_access_token",
359
- "expiration_date": "2010-03-07T00:00:00.000Z",
360
- "expires_in": 86400,
361
- "refresh_token": "a_refresh_token",
362
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
363
- "refresh_token_expires_in": 5364748800,
364
- "token_type": "bearer",
365
- },
366
- "headers": {
367
- "connection": undefined,
368
- "content-type": "application/json",
369
- "date": undefined,
370
- "etag": undefined,
371
- "keep-alive": undefined,
372
- "last-modified": undefined,
373
- "server": undefined,
374
- "transaction-id": "0",
375
- "transfer-encoding": "chunked",
376
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
377
- },
378
- "status": 200,
379
- }
380
- `);
366
+ {
367
+ "data": {
368
+ "access_token": "an_access_token",
369
+ "expiration_date": "2010-03-07T00:00:00.000Z",
370
+ "expires_in": 86400,
371
+ "refresh_token": "a_refresh_token",
372
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
373
+ "refresh_token_expires_in": 5364748800,
374
+ "token_type": "bearer",
375
+ },
376
+ "headers": {
377
+ "connection": undefined,
378
+ "content-type": "application/json",
379
+ "date": undefined,
380
+ "etag": undefined,
381
+ "keep-alive": undefined,
382
+ "last-modified": undefined,
383
+ "server": undefined,
384
+ "transaction-id": "0",
385
+ "transfer-encoding": "chunked",
386
+ "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
387
+ },
388
+ "status": 200,
389
+ }
390
+ `);
381
391
  expect({
382
392
  checkApplicationCalls: checkApplication.mock.calls,
383
393
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -458,31 +468,31 @@ describe('OAuth2 server', () => {
458
468
  },
459
469
  data,
460
470
  }).toMatchInlineSnapshot(`
461
- {
462
- "data": {
463
- "access_token": "an_access_token",
464
- "expiration_date": "2010-03-07T00:00:00.000Z",
465
- "expires_in": 86400,
466
- "refresh_token": "a_refresh_token",
467
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
468
- "refresh_token_expires_in": 5364748800,
469
- "token_type": "bearer",
470
- },
471
- "headers": {
472
- "connection": undefined,
473
- "content-type": "application/json",
474
- "date": undefined,
475
- "etag": undefined,
476
- "keep-alive": undefined,
477
- "last-modified": undefined,
478
- "server": undefined,
479
- "transaction-id": "1",
480
- "transfer-encoding": "chunked",
481
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
482
- },
483
- "status": 200,
484
- }
485
- `);
471
+ {
472
+ "data": {
473
+ "access_token": "an_access_token",
474
+ "expiration_date": "2010-03-07T00:00:00.000Z",
475
+ "expires_in": 86400,
476
+ "refresh_token": "a_refresh_token",
477
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
478
+ "refresh_token_expires_in": 5364748800,
479
+ "token_type": "bearer",
480
+ },
481
+ "headers": {
482
+ "connection": undefined,
483
+ "content-type": "application/json",
484
+ "date": undefined,
485
+ "etag": undefined,
486
+ "keep-alive": undefined,
487
+ "last-modified": undefined,
488
+ "server": undefined,
489
+ "transaction-id": "1",
490
+ "transfer-encoding": "chunked",
491
+ "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
492
+ },
493
+ "status": 200,
494
+ }
495
+ `);
486
496
  expect({
487
497
  checkApplicationCalls: checkApplication.mock.calls,
488
498
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -558,31 +568,31 @@ describe('OAuth2 server', () => {
558
568
  },
559
569
  data,
560
570
  }).toMatchInlineSnapshot(`
561
- {
562
- "data": {
563
- "access_token": "an_access_token",
564
- "expiration_date": "2010-03-07T00:00:00.000Z",
565
- "expires_in": 86400,
566
- "refresh_token": "a_refresh_token",
567
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
568
- "refresh_token_expires_in": 5364748800,
569
- "token_type": "bearer",
570
- },
571
- "headers": {
572
- "connection": undefined,
573
- "content-type": "application/json",
574
- "date": undefined,
575
- "etag": undefined,
576
- "keep-alive": undefined,
577
- "last-modified": undefined,
578
- "server": undefined,
579
- "transaction-id": "2",
580
- "transfer-encoding": "chunked",
581
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
582
- },
583
- "status": 200,
584
- }
585
- `);
571
+ {
572
+ "data": {
573
+ "access_token": "an_access_token",
574
+ "expiration_date": "2010-03-07T00:00:00.000Z",
575
+ "expires_in": 86400,
576
+ "refresh_token": "a_refresh_token",
577
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
578
+ "refresh_token_expires_in": 5364748800,
579
+ "token_type": "bearer",
580
+ },
581
+ "headers": {
582
+ "connection": undefined,
583
+ "content-type": "application/json",
584
+ "date": undefined,
585
+ "etag": undefined,
586
+ "keep-alive": undefined,
587
+ "last-modified": undefined,
588
+ "server": undefined,
589
+ "transaction-id": "2",
590
+ "transfer-encoding": "chunked",
591
+ "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
592
+ },
593
+ "status": 200,
594
+ }
595
+ `);
586
596
  expect({
587
597
  checkApplicationCalls: checkApplication.mock.calls,
588
598
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -617,7 +627,7 @@ describe('OAuth2 server', () => {
617
627
  applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
618
628
  scope: 'user,oauth',
619
629
  redirectURI:
620
- 'https://example.com/oauth2/callback?a_param=a_param_value',
630
+ 'https://redirect.example.com/oauth2/callback?a_param=a_param_value',
621
631
  });
622
632
 
623
633
  const { status, headers, data } = await axios({
@@ -649,22 +659,22 @@ describe('OAuth2 server', () => {
649
659
  },
650
660
  data,
651
661
  }).toMatchInlineSnapshot(`
652
- {
653
- "data": "",
654
- "headers": {
655
- "connection": undefined,
656
- "date": undefined,
657
- "etag": undefined,
658
- "keep-alive": undefined,
659
- "last-modified": undefined,
660
- "location": "https://auth.example.com/sign_in?type=code&redirect_uri=https%3A%2F%2Fexample.com%2Foauth2%2Fcallback%3Fa_param%3Da_param_value&scope=user&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&state=xyz",
661
- "server": undefined,
662
- "transaction-id": "3",
663
- "transfer-encoding": "chunked",
664
- },
665
- "status": 302,
666
- }
667
- `);
662
+ {
663
+ "data": "",
664
+ "headers": {
665
+ "connection": undefined,
666
+ "date": undefined,
667
+ "etag": undefined,
668
+ "keep-alive": undefined,
669
+ "last-modified": undefined,
670
+ "location": "https://auth.example.com/sign_in?type=code&redirect_uri=https%3A%2F%2Fredirect.example.com%2Foauth2%2Fcallback%3Fa_param%3Da_param_value&scope=user&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&state=xyz",
671
+ "server": undefined,
672
+ "transaction-id": "3",
673
+ "transfer-encoding": "chunked",
674
+ },
675
+ "status": 302,
676
+ }
677
+ `);
668
678
  expect({
669
679
  checkApplicationCalls: checkApplication.mock.calls,
670
680
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -735,23 +745,23 @@ describe('OAuth2 server', () => {
735
745
  },
736
746
  data,
737
747
  }).toMatchInlineSnapshot(`
738
- {
739
- "data": "",
740
- "headers": {
741
- "connection": undefined,
742
- "date": undefined,
743
- "etag": undefined,
744
- "keep-alive": undefined,
745
- "last-modified": undefined,
746
- "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&user_id=2&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo%3Fa_param%3Da_value&code=a_code",
747
- "server": undefined,
748
- "transaction-id": "4",
749
- "transfer-encoding": "chunked",
750
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
751
- },
752
- "status": 302,
753
- }
754
- `);
748
+ {
749
+ "data": "",
750
+ "headers": {
751
+ "connection": undefined,
752
+ "date": undefined,
753
+ "etag": undefined,
754
+ "keep-alive": undefined,
755
+ "last-modified": undefined,
756
+ "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&code=a_code",
757
+ "server": undefined,
758
+ "transaction-id": "4",
759
+ "transfer-encoding": "chunked",
760
+ "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
761
+ },
762
+ "status": 302,
763
+ }
764
+ `);
755
765
  expect({
756
766
  checkApplicationCalls: checkApplication.mock.calls,
757
767
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -830,31 +840,31 @@ describe('OAuth2 server', () => {
830
840
  },
831
841
  data,
832
842
  }).toMatchInlineSnapshot(`
833
- {
834
- "data": {
835
- "access_token": "an_access_token",
836
- "expiration_date": "2010-03-07T00:00:00.000Z",
837
- "expires_in": 86400,
838
- "refresh_token": "a_refresh_token",
839
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
840
- "refresh_token_expires_in": 5364748800,
841
- "token_type": "bearer",
842
- },
843
- "headers": {
844
- "connection": undefined,
845
- "content-type": "application/json",
846
- "date": undefined,
847
- "etag": undefined,
848
- "keep-alive": undefined,
849
- "last-modified": undefined,
850
- "server": undefined,
851
- "transaction-id": "5",
852
- "transfer-encoding": "chunked",
853
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
854
- },
855
- "status": 200,
856
- }
857
- `);
843
+ {
844
+ "data": {
845
+ "access_token": "an_access_token",
846
+ "expiration_date": "2010-03-07T00:00:00.000Z",
847
+ "expires_in": 86400,
848
+ "refresh_token": "a_refresh_token",
849
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
850
+ "refresh_token_expires_in": 5364748800,
851
+ "token_type": "bearer",
852
+ },
853
+ "headers": {
854
+ "connection": undefined,
855
+ "content-type": "application/json",
856
+ "date": undefined,
857
+ "etag": undefined,
858
+ "keep-alive": undefined,
859
+ "last-modified": undefined,
860
+ "server": undefined,
861
+ "transaction-id": "5",
862
+ "transfer-encoding": "chunked",
863
+ "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
864
+ },
865
+ "status": 200,
866
+ }
867
+ `);
858
868
  expect({
859
869
  checkApplicationCalls: checkApplication.mock.calls,
860
870
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -919,22 +929,22 @@ describe('OAuth2 server', () => {
919
929
  },
920
930
  data,
921
931
  }).toMatchInlineSnapshot(`
922
- {
923
- "data": "",
924
- "headers": {
925
- "connection": undefined,
926
- "date": undefined,
927
- "etag": undefined,
928
- "keep-alive": undefined,
929
- "last-modified": undefined,
930
- "location": "https://auth.example.com/sign_in?type=token&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&scope=user&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&state=xyz",
931
- "server": undefined,
932
- "transaction-id": "6",
933
- "transfer-encoding": "chunked",
934
- },
935
- "status": 302,
936
- }
937
- `);
932
+ {
933
+ "data": "",
934
+ "headers": {
935
+ "connection": undefined,
936
+ "date": undefined,
937
+ "etag": undefined,
938
+ "keep-alive": undefined,
939
+ "last-modified": undefined,
940
+ "location": "https://auth.example.com/sign_in?type=token&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&scope=user&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&state=xyz",
941
+ "server": undefined,
942
+ "transaction-id": "6",
943
+ "transfer-encoding": "chunked",
944
+ },
945
+ "status": 302,
946
+ }
947
+ `);
938
948
  expect({
939
949
  checkApplicationCalls: checkApplication.mock.calls,
940
950
  authenticationCheckCalls: authentication.check.mock.calls,
@@ -1014,23 +1024,23 @@ describe('OAuth2 server', () => {
1014
1024
  },
1015
1025
  data,
1016
1026
  }).toMatchInlineSnapshot(`
1017
- {
1018
- "data": "",
1019
- "headers": {
1020
- "connection": undefined,
1021
- "date": undefined,
1022
- "etag": undefined,
1023
- "keep-alive": undefined,
1024
- "last-modified": undefined,
1025
- "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&user_id=2&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&access_token=an_access_token&token_type=bearer&expires_in=86400",
1026
- "server": undefined,
1027
- "transaction-id": "7",
1028
- "transfer-encoding": "chunked",
1029
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
1030
- },
1031
- "status": 302,
1032
- }
1033
- `);
1027
+ {
1028
+ "data": "",
1029
+ "headers": {
1030
+ "connection": undefined,
1031
+ "date": undefined,
1032
+ "etag": undefined,
1033
+ "keep-alive": undefined,
1034
+ "last-modified": undefined,
1035
+ "location": "http://redirect.example.com/yolo?client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&access_token=an_access_token&token_type=bearer&expires_in=86400",
1036
+ "server": undefined,
1037
+ "transaction-id": "7",
1038
+ "transfer-encoding": "chunked",
1039
+ "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
1040
+ },
1041
+ "status": 302,
1042
+ }
1043
+ `);
1034
1044
  expect({
1035
1045
  checkApplicationCalls: checkApplication.mock.calls,
1036
1046
  authenticationCheckCalls: authentication.check.mock.calls,
package/src/index.ts CHANGED
@@ -5,29 +5,40 @@ import initGetOAuth2Authorize, {
5
5
  redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,
6
6
  scopeParameter as getOAuth2AuthorizeScopeParameter,
7
7
  stateParameter as getOAuth2AuthorizeStateParameter,
8
+ codeChallengeSchema as getOAuth2AuthorizeCodeChallengeSchema,
9
+ codeChallengeParameter as getOAuth2AuthorizeCodeChallengeParameter,
10
+ codeChallengeMethodSchema as getOAuth2AuthorizeCodeChallengeMethodSchema,
11
+ codeChallengeMethodParameter as getOAuth2AuthorizeCodeChallengeMethodParameter,
8
12
  } from './routes/getOAuth2Authorize.js';
9
13
  import initPostOAuth2Acknowledge, {
10
14
  definition as postOAuth2AcknowledgeDefinition,
11
15
  } from './routes/postOAuth2Acknowledge.js';
12
16
  import initPostOAuth2Token, {
13
17
  definition as postOAuth2TokenDefinition,
18
+ codeVerifierSchema as postOAuth2TokenCodeVerifierSchema,
14
19
  authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
15
20
  passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema,
16
21
  clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,
17
22
  refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,
18
23
  tokenBodySchema as postOAuth2TokenTokenBodySchema,
19
24
  } from './routes/postOAuth2Token.js';
25
+ import initGetOAuth2WellKnown, {
26
+ definition as getOAuth2WellKnownDefinition,
27
+ endpointAuthenticationMethodsSchema as getOAuth2WellKnownEndpointAuthenticationMethodsSchema,
28
+ jsonWebAlgorithmsSchema as getOAuth2WellKnownJsonWebAlgorithmsSchema,
29
+ jsonWebEncryptionsSchema as getOAuth2WellKnownJsonWebEncryptionsSchema,
30
+ httpsProtocolURISchema as getOAuth2WellKnownHTTPSProtocolURISchema,
31
+ oAuth2MetadataSchema as getOAuth2WellKnownOAuth2MetadataSchema,
32
+ } from './routes/getOAuth2WellKnownMetadata.js';
20
33
  import initOAuth2Granters, {
21
34
  type OAuth2YErrorRegistry,
22
35
  OAUTH2_ERRORS_DESCRIPTORS,
23
36
  } from './services/oAuth2Granters.js';
24
37
  import initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter.js';
25
- import initOAuth2CodeGranter from './services/oAuth2CodeGranter.js';
26
38
  import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter.js';
27
39
  import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter.js';
28
40
  import initOAuth2TokenGranter from './services/oAuth2TokenGranter.js';
29
41
  import {
30
- type OAuth2CodeService,
31
42
  type OAuth2PasswordService,
32
43
  type OAuth2AccessTokenService,
33
44
  type OAuth2RefreshTokenService,
@@ -55,6 +66,12 @@ import {
55
66
  type AuthCookiesData,
56
67
  type AuthHandlersConfig,
57
68
  } from './services/authCookies.js';
69
+ import initOAuth2CodeGranter, {
70
+ base64UrlEncode,
71
+ hashCodeVerifier,
72
+ type CodeChallengeMethod,
73
+ type OAuth2CodeService,
74
+ } from './services/oAuth2CodeGranter.js';
58
75
 
59
76
  declare module 'yerror' {
60
77
  interface YErrorRegistry extends OAuth2YErrorRegistry {
@@ -64,6 +81,7 @@ declare module 'yerror' {
64
81
 
65
82
  export type {
66
83
  OAuth2YErrorRegistry,
84
+ CodeChallengeMethod,
67
85
  OAuth2CodeService,
68
86
  OAuth2PasswordService,
69
87
  OAuth2AccessTokenService,
@@ -85,10 +103,24 @@ export {
85
103
  getOAuth2AuthorizeRedirectURIParameter,
86
104
  getOAuth2AuthorizeScopeParameter,
87
105
  getOAuth2AuthorizeStateParameter,
106
+ getOAuth2AuthorizeCodeChallengeSchema,
107
+ getOAuth2AuthorizeCodeChallengeMethodSchema,
108
+ getOAuth2AuthorizeCodeChallengeParameter,
109
+ getOAuth2AuthorizeCodeChallengeMethodParameter,
110
+ initGetOAuth2WellKnown,
111
+ getOAuth2WellKnownDefinition,
112
+ getOAuth2WellKnownEndpointAuthenticationMethodsSchema,
113
+ getOAuth2WellKnownJsonWebAlgorithmsSchema,
114
+ getOAuth2WellKnownJsonWebEncryptionsSchema,
115
+ getOAuth2WellKnownHTTPSProtocolURISchema,
116
+ getOAuth2WellKnownOAuth2MetadataSchema,
117
+ base64UrlEncode,
118
+ hashCodeVerifier,
88
119
  initPostOAuth2Acknowledge,
89
120
  postOAuth2AcknowledgeDefinition,
90
121
  initPostOAuth2Token,
91
122
  postOAuth2TokenDefinition,
123
+ postOAuth2TokenCodeVerifierSchema,
92
124
  postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
93
125
  postOAuth2TokenPasswordTokenRequestBodySchema,
94
126
  postOAuth2TokenClientCredentialsTokenRequestBodySchema,
@@ -28,8 +28,7 @@ exports[`getOAuth2Authorize should redirect with an error when some 2`] = `
28
28
  "logCalls": [
29
29
  [
30
30
  "debug",
31
- "👫 - OAuth2 initialization error",
32
- "E_UNKNOWN_AUTHORIZER_TYPE",
31
+ "👫 - OAuth2 authorize error.",
33
32
  ],
34
33
  ],
35
34
  "tokenGranterAcknowledgerAcknowledgeCalls": [],