@whook/oauth2 9.0.0 → 10.0.1

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 (131) hide show
  1. package/README.md +90 -68
  2. package/dist/handlers/getOAuth2Authorize.d.ts +4 -4
  3. package/dist/handlers/getOAuth2Authorize.js +122 -165
  4. package/dist/handlers/getOAuth2Authorize.js.map +1 -1
  5. package/dist/handlers/getOAuth2Authorize.test.js +117 -103
  6. package/dist/handlers/getOAuth2Authorize.test.js.map +1 -1
  7. package/dist/handlers/postAuthLogin.d.ts +1 -1
  8. package/dist/handlers/postAuthLogin.js +83 -121
  9. package/dist/handlers/postAuthLogin.js.map +1 -1
  10. package/dist/handlers/postAuthLogin.test.js +42 -44
  11. package/dist/handlers/postAuthLogin.test.js.map +1 -1
  12. package/dist/handlers/postAuthLogout.d.ts +1 -1
  13. package/dist/handlers/postAuthLogout.js +26 -42
  14. package/dist/handlers/postAuthLogout.js.map +1 -1
  15. package/dist/handlers/postAuthLogout.test.js +19 -21
  16. package/dist/handlers/postAuthLogout.test.js.map +1 -1
  17. package/dist/handlers/postAuthRefresh.d.ts +1 -1
  18. package/dist/handlers/postAuthRefresh.js +93 -132
  19. package/dist/handlers/postAuthRefresh.js.map +1 -1
  20. package/dist/handlers/postAuthRefresh.test.js +47 -49
  21. package/dist/handlers/postAuthRefresh.test.js.map +1 -1
  22. package/dist/handlers/postOAuth2Acknowledge.d.ts +5 -5
  23. package/dist/handlers/postOAuth2Acknowledge.js +119 -151
  24. package/dist/handlers/postOAuth2Acknowledge.js.map +1 -1
  25. package/dist/handlers/postOAuth2Acknowledge.test.js +139 -125
  26. package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -1
  27. package/dist/handlers/postOAuth2Token.d.ts +1 -1
  28. package/dist/handlers/postOAuth2Token.js +200 -232
  29. package/dist/handlers/postOAuth2Token.js.map +1 -1
  30. package/dist/handlers/postOAuth2Token.test.js +156 -153
  31. package/dist/handlers/postOAuth2Token.test.js.map +1 -1
  32. package/dist/index.d.ts +16 -16
  33. package/dist/index.js +14 -229
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.test.js +697 -619
  36. package/dist/index.test.js.map +1 -1
  37. package/dist/services/authCookies.d.ts +8 -4
  38. package/dist/services/authCookies.js +40 -71
  39. package/dist/services/authCookies.js.map +1 -1
  40. package/dist/services/authCookies.test.js +57 -62
  41. package/dist/services/authCookies.test.js.map +1 -1
  42. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +2 -2
  43. package/dist/services/oAuth2ClientCredentialsGranter.js +34 -52
  44. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  45. package/dist/services/oAuth2CodeGranter.d.ts +1 -1
  46. package/dist/services/oAuth2CodeGranter.js +66 -109
  47. package/dist/services/oAuth2CodeGranter.js.map +1 -1
  48. package/dist/services/oAuth2CodeGranter.test.js +65 -66
  49. package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
  50. package/dist/services/oAuth2Granters.js +131 -138
  51. package/dist/services/oAuth2Granters.js.map +1 -1
  52. package/dist/services/oAuth2PasswordGranter.d.ts +1 -1
  53. package/dist/services/oAuth2PasswordGranter.js +27 -52
  54. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  55. package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -1
  56. package/dist/services/oAuth2RefreshTokenGranter.js +34 -58
  57. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  58. package/dist/services/oAuth2TokenGranter.d.ts +1 -1
  59. package/dist/services/oAuth2TokenGranter.js +50 -86
  60. package/dist/services/oAuth2TokenGranter.js.map +1 -1
  61. package/package.json +48 -89
  62. package/src/__snapshots__/index.test.ts.snap +23 -22
  63. package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +1 -1
  64. package/src/handlers/getOAuth2Authorize.test.ts +49 -13
  65. package/src/handlers/getOAuth2Authorize.ts +2 -2
  66. package/src/handlers/postAuthLogin.test.ts +9 -5
  67. package/src/handlers/postAuthLogin.ts +4 -4
  68. package/src/handlers/postAuthLogout.test.ts +8 -4
  69. package/src/handlers/postAuthLogout.ts +2 -2
  70. package/src/handlers/postAuthRefresh.test.ts +10 -6
  71. package/src/handlers/postAuthRefresh.ts +4 -4
  72. package/src/handlers/postOAuth2Acknowledge.test.ts +83 -35
  73. package/src/handlers/postOAuth2Acknowledge.ts +18 -8
  74. package/src/handlers/postOAuth2Token.test.ts +77 -17
  75. package/src/handlers/postOAuth2Token.ts +3 -3
  76. package/src/index.test.ts +110 -65
  77. package/src/index.ts +21 -19
  78. package/src/services/authCookies.test.ts +2 -2
  79. package/src/services/authCookies.ts +10 -5
  80. package/src/services/oAuth2ClientCredentialsGranter.ts +3 -3
  81. package/src/services/oAuth2CodeGranter.test.ts +27 -4
  82. package/src/services/oAuth2CodeGranter.ts +2 -2
  83. package/src/services/oAuth2PasswordGranter.ts +2 -2
  84. package/src/services/oAuth2RefreshTokenGranter.ts +2 -2
  85. package/src/services/oAuth2TokenGranter.ts +1 -1
  86. package/dist/handlers/getOAuth2Authorize.mjs +0 -160
  87. package/dist/handlers/getOAuth2Authorize.mjs.map +0 -1
  88. package/dist/handlers/getOAuth2Authorize.test.mjs +0 -114
  89. package/dist/handlers/getOAuth2Authorize.test.mjs.map +0 -1
  90. package/dist/handlers/postAuthLogin.mjs +0 -109
  91. package/dist/handlers/postAuthLogin.mjs.map +0 -1
  92. package/dist/handlers/postAuthLogin.test.mjs +0 -85
  93. package/dist/handlers/postAuthLogin.test.mjs.map +0 -1
  94. package/dist/handlers/postAuthLogout.mjs +0 -33
  95. package/dist/handlers/postAuthLogout.mjs.map +0 -1
  96. package/dist/handlers/postAuthLogout.test.mjs +0 -30
  97. package/dist/handlers/postAuthLogout.test.mjs.map +0 -1
  98. package/dist/handlers/postAuthRefresh.mjs +0 -122
  99. package/dist/handlers/postAuthRefresh.mjs.map +0 -1
  100. package/dist/handlers/postAuthRefresh.test.mjs +0 -94
  101. package/dist/handlers/postAuthRefresh.test.mjs.map +0 -1
  102. package/dist/handlers/postOAuth2Acknowledge.mjs +0 -150
  103. package/dist/handlers/postOAuth2Acknowledge.mjs.map +0 -1
  104. package/dist/handlers/postOAuth2Acknowledge.test.mjs +0 -140
  105. package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +0 -1
  106. package/dist/handlers/postOAuth2Token.mjs +0 -231
  107. package/dist/handlers/postOAuth2Token.mjs.map +0 -1
  108. package/dist/handlers/postOAuth2Token.test.mjs +0 -160
  109. package/dist/handlers/postOAuth2Token.test.mjs.map +0 -1
  110. package/dist/index.mjs +0 -15
  111. package/dist/index.mjs.map +0 -1
  112. package/dist/index.test.mjs +0 -747
  113. package/dist/index.test.mjs.map +0 -1
  114. package/dist/services/authCookies.mjs +0 -58
  115. package/dist/services/authCookies.mjs.map +0 -1
  116. package/dist/services/authCookies.test.mjs +0 -77
  117. package/dist/services/authCookies.test.mjs.map +0 -1
  118. package/dist/services/oAuth2ClientCredentialsGranter.mjs +0 -41
  119. package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +0 -1
  120. package/dist/services/oAuth2CodeGranter.mjs +0 -98
  121. package/dist/services/oAuth2CodeGranter.mjs.map +0 -1
  122. package/dist/services/oAuth2CodeGranter.test.mjs +0 -83
  123. package/dist/services/oAuth2CodeGranter.test.mjs.map +0 -1
  124. package/dist/services/oAuth2Granters.mjs +0 -127
  125. package/dist/services/oAuth2Granters.mjs.map +0 -1
  126. package/dist/services/oAuth2PasswordGranter.mjs +0 -40
  127. package/dist/services/oAuth2PasswordGranter.mjs.map +0 -1
  128. package/dist/services/oAuth2RefreshTokenGranter.mjs +0 -47
  129. package/dist/services/oAuth2RefreshTokenGranter.mjs.map +0 -1
  130. package/dist/services/oAuth2TokenGranter.mjs +0 -78
  131. package/dist/services/oAuth2TokenGranter.mjs.map +0 -1
@@ -1,56 +1,38 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _knifecycle = require("knifecycle");
9
-
10
- var _whook = require("@whook/whook");
11
-
12
- var _yerror = _interopRequireDefault(require("yerror"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- var _default = (0, _knifecycle.service)(initOAuth2ClientCredentialsGranter, "oAuth2ClientCredentialsGranter", ["OAUTH2", "checkApplication", "?log"]); // Client Credentials Grant
1
+ import { autoService } from 'knifecycle';
2
+ import { noop } from '@whook/whook';
3
+ import { YError } from 'yerror';
4
+ export default autoService(initOAuth2ClientCredentialsGranter);
5
+ // Client Credentials Grant
17
6
  // https://tools.ietf.org/html/rfc6749#section-4.4
18
-
19
-
20
- exports.default = _default;
21
-
22
- async function initOAuth2ClientCredentialsGranter({
23
- OAUTH2,
24
- checkApplication,
25
- log = _whook.noop
26
- }) {
27
- const authenticateWithClientCredentials = async ({
28
- scope: demandedScope = ''
29
- }, authenticationData) => {
30
- // The client must be authenticated
31
- if (!authenticationData) {
32
- throw new _yerror.default('E_UNAUTHORIZED');
33
- } // Checking the scope and availability of the demanded
34
- // grant type
35
-
36
-
37
- await checkApplication({
38
- applicationId: authenticationData.applicationId,
39
- type: 'client_credentials',
40
- scope: demandedScope
41
- });
42
- return { ...authenticationData,
43
- scope: demandedScope ? demandedScope : OAUTH2.defaultToClientScope ? authenticationData.scope : ''
7
+ async function initOAuth2ClientCredentialsGranter({ OAUTH2, checkApplication, log = noop, }) {
8
+ const authenticateWithClientCredentials = async ({ scope: demandedScope = '' }, authenticationData) => {
9
+ // The client must be authenticated
10
+ if (!authenticationData) {
11
+ throw new YError('E_UNAUTHORIZED');
12
+ }
13
+ // Checking the scope and availability of the demanded
14
+ // grant type
15
+ await checkApplication({
16
+ applicationId: authenticationData.applicationId,
17
+ type: 'client_credentials',
18
+ scope: demandedScope,
19
+ });
20
+ return {
21
+ ...authenticationData,
22
+ scope: demandedScope
23
+ ? demandedScope
24
+ : OAUTH2.defaultToClientScope
25
+ ? authenticationData.scope
26
+ : '',
27
+ };
28
+ };
29
+ log('debug', '👫 - OAuth2ClientCredentialsGranter Service Initialized!');
30
+ return {
31
+ type: 'client_credentials',
32
+ authenticator: {
33
+ grantType: 'client_credentials',
34
+ authenticate: authenticateWithClientCredentials,
35
+ },
44
36
  };
45
- };
46
-
47
- log('debug', '👫 - OAuth2ClientCredentialsGranter Service Initialized!');
48
- return {
49
- type: 'client_credentials',
50
- authenticator: {
51
- grantType: 'client_credentials',
52
- authenticate: authenticateWithClientCredentials
53
- }
54
- };
55
37
  }
56
38
  //# sourceMappingURL=oAuth2ClientCredentialsGranter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oAuth2ClientCredentialsGranter.js","names":["autoService","initOAuth2ClientCredentialsGranter","OAUTH2","checkApplication","log","noop","authenticateWithClientCredentials","scope","demandedScope","authenticationData","YError","applicationId","type","defaultToClientScope","authenticator","grantType","authenticate"],"sources":["../../src/services/oAuth2ClientCredentialsGranter.ts"],"sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\nimport type { OAuth2Options } from '..';\n\nexport type OAuth2ClientCredentialsGranterDependencies = {\n OAUTH2: OAuth2Options;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2ClientCredentialsGranterParameters<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = {\n username: string;\n password: string;\n scope?: AUTHENTICATION_DATA['scope'];\n};\nexport type OAuth2ClientCredentialsGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2ClientCredentialsGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2ClientCredentialsGranter);\n\n// Client Credentials Grant\n// https://tools.ietf.org/html/rfc6749#section-4.4\nasync function initOAuth2ClientCredentialsGranter({\n OAUTH2,\n checkApplication,\n log = noop,\n}: OAuth2ClientCredentialsGranterDependencies): Promise<OAuth2ClientCredentialsGranterService> {\n const authenticateWithClientCredentials: NonNullable<\n OAuth2ClientCredentialsGranterService['authenticator']\n >['authenticate'] = async (\n { scope: demandedScope = '' },\n authenticationData,\n ) => {\n // The client must be authenticated\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // Checking the scope and availability of the demanded\n // grant type\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'client_credentials',\n scope: demandedScope,\n });\n\n return {\n ...authenticationData,\n scope: demandedScope\n ? demandedScope\n : OAUTH2.defaultToClientScope\n ? authenticationData.scope\n : '',\n };\n };\n\n log('debug', '👫 - OAuth2ClientCredentialsGranter Service Initialized!');\n\n return {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\n authenticate: authenticateWithClientCredentials,\n },\n };\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;eA8Be,IAAAA,mBAAA,EAAYC,kCAAZ,2E,EAEf;AACA;;;;;AACA,eAAeA,kCAAf,CAAkD;EAChDC,MADgD;EAEhDC,gBAFgD;EAGhDC,GAAG,GAAGC;AAH0C,CAAlD,EAI+F;EAC7F,MAAMC,iCAEW,GAAG,OAClB;IAAEC,KAAK,EAAEC,aAAa,GAAG;EAAzB,CADkB,EAElBC,kBAFkB,KAGf;IACH;IACA,IAAI,CAACA,kBAAL,EAAyB;MACvB,MAAM,IAAIC,eAAJ,CAAW,gBAAX,CAAN;IACD,CAJE,CAMH;IACA;;;IACA,MAAMP,gBAAgB,CAAC;MACrBQ,aAAa,EAAEF,kBAAkB,CAACE,aADb;MAErBC,IAAI,EAAE,oBAFe;MAGrBL,KAAK,EAAEC;IAHc,CAAD,CAAtB;IAMA,OAAO,EACL,GAAGC,kBADE;MAELF,KAAK,EAAEC,aAAa,GAChBA,aADgB,GAEhBN,MAAM,CAACW,oBAAP,GACAJ,kBAAkB,CAACF,KADnB,GAEA;IANC,CAAP;EAQD,CA3BD;;EA6BAH,GAAG,CAAC,OAAD,EAAU,0DAAV,CAAH;EAEA,OAAO;IACLQ,IAAI,EAAE,oBADD;IAELE,aAAa,EAAE;MACbC,SAAS,EAAE,oBADE;MAEbC,YAAY,EAAEV;IAFD;EAFV,CAAP;AAOD"}
1
+ {"version":3,"file":"oAuth2ClientCredentialsGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2ClientCredentialsGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AA8BhC,eAAe,WAAW,CAAC,kCAAkC,CAAC,CAAC;AAE/D,2BAA2B;AAC3B,kDAAkD;AAClD,KAAK,UAAU,kCAAkC,CAAC,EAChD,MAAM,EACN,gBAAgB,EAChB,GAAG,GAAG,IAAI,GACiC;IAC3C,MAAM,iCAAiC,GAEnB,KAAK,EACvB,EAAE,KAAK,EAAE,aAAa,GAAG,EAAE,EAAE,EAC7B,kBAAkB,EAClB,EAAE;QACF,mCAAmC;QACnC,IAAI,CAAC,kBAAkB,EAAE;YACvB,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;SACpC;QAED,sDAAsD;QACtD,aAAa;QACb,MAAM,gBAAgB,CAAC;YACrB,aAAa,EAAE,kBAAkB,CAAC,aAAa;YAC/C,IAAI,EAAE,oBAAoB;YAC1B,KAAK,EAAE,aAAa;SACrB,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,kBAAkB;YACrB,KAAK,EAAE,aAAa;gBAClB,CAAC,CAAC,aAAa;gBACf,CAAC,CAAC,MAAM,CAAC,oBAAoB;oBAC7B,CAAC,CAAC,kBAAkB,CAAC,KAAK;oBAC1B,CAAC,CAAC,EAAE;SACP,CAAC;IACJ,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,0DAA0D,CAAC,CAAC;IAEzE,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,aAAa,EAAE;YACb,SAAS,EAAE,oBAAoB;YAC/B,YAAY,EAAE,iCAAiC;SAChD;KACF,CAAC;AACJ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { LogService } from 'common-services';
2
- import type { OAuth2GranterService, OAuth2CodeService, CheckApplicationService } from './oAuth2Granters';
2
+ import type { OAuth2GranterService, OAuth2CodeService, CheckApplicationService } from './oAuth2Granters.js';
3
3
  import type { BaseAuthenticationData } from '@whook/authorization';
4
4
  export declare const CODE_GRANTER_TYPE = "code";
5
5
  export declare type OAuth2CodeGranterDependencies = {
@@ -1,115 +1,72 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.CODE_GRANTER_TYPE = void 0;
7
-
8
- var _knifecycle = require("knifecycle");
9
-
10
- var _whook = require("@whook/whook");
11
-
12
- var _yerror = _interopRequireDefault(require("yerror"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const CODE_GRANTER_TYPE = 'code';
17
- exports.CODE_GRANTER_TYPE = CODE_GRANTER_TYPE;
18
-
19
- var _default = (0, _knifecycle.service)(initOAuth2CodeGranter, "oAuth2CodeGranter", ["oAuth2Code", "checkApplication", "?log"]); // Authorization Code Grant
1
+ import { autoService } from 'knifecycle';
2
+ import { noop } from '@whook/whook';
3
+ import { YError } from 'yerror';
4
+ export const CODE_GRANTER_TYPE = 'code';
5
+ export default autoService(initOAuth2CodeGranter);
6
+ // Authorization Code Grant
20
7
  // https://tools.ietf.org/html/rfc6749#section-4.1
21
-
22
-
23
- exports.default = _default;
24
-
25
- async function initOAuth2CodeGranter({
26
- oAuth2Code,
27
- checkApplication,
28
- log = _whook.noop
29
- }) {
30
- const authorizeWithCode = async ({
31
- clientId,
32
- redirectURI,
33
- scope = ''
34
- }) => {
35
- const {
36
- redirectURI: finalRedirectURI
37
- } = await checkApplication({
38
- applicationId: clientId,
39
- type: CODE_GRANTER_TYPE,
40
- redirectURI,
41
- scope
42
- });
43
- return {
44
- applicationId: clientId,
45
- redirectURI: finalRedirectURI,
46
- scope
8
+ async function initOAuth2CodeGranter({ oAuth2Code, checkApplication, log = noop, }) {
9
+ const authorizeWithCode = async ({ clientId, redirectURI, scope = '' }) => {
10
+ const { redirectURI: finalRedirectURI } = await checkApplication({
11
+ applicationId: clientId,
12
+ type: CODE_GRANTER_TYPE,
13
+ redirectURI,
14
+ scope,
15
+ });
16
+ return {
17
+ applicationId: clientId,
18
+ redirectURI: finalRedirectURI,
19
+ scope,
20
+ };
21
+ };
22
+ // Authorization Code Response:
23
+ // https://tools.ietf.org/html/rfc6749#section-4.1.2
24
+ const acknowledgeWithCode = async (authenticationData, { clientId, redirectURI, scope }, additionalParameters) => {
25
+ const code = await oAuth2Code.create({ ...authenticationData, applicationId: clientId, scope }, redirectURI, additionalParameters);
26
+ return {
27
+ applicationId: clientId,
28
+ redirectURI,
29
+ scope,
30
+ code,
31
+ };
32
+ };
33
+ const authenticateWithCode = async ({ code, clientId, redirectURI }, authenticationData) => {
34
+ // The client must be authenticated (for now, see below)
35
+ if (!authenticationData) {
36
+ throw new YError('E_UNAUTHORIZED');
37
+ }
38
+ // This check is not really necessary atm but it acts
39
+ // as a reminder that this grant type could be used
40
+ // without authenticating the client. In this
41
+ // scenario, the authenticationData should be deducted
42
+ // from the clientId and the code given in parameters
43
+ // See https://tools.ietf.org/html/rfc6749#section-4.1.3
44
+ if (clientId && clientId !== authenticationData.applicationId) {
45
+ throw new YError('E_UNAUTHORIZED', clientId, authenticationData.applicationId);
46
+ }
47
+ await checkApplication({
48
+ applicationId: authenticationData.applicationId,
49
+ type: CODE_GRANTER_TYPE,
50
+ scope: '',
51
+ });
52
+ const newAuthenticationData = await oAuth2Code.check(authenticationData, code, redirectURI);
53
+ return newAuthenticationData;
47
54
  };
48
- }; // Authorization Code Response:
49
- // https://tools.ietf.org/html/rfc6749#section-4.1.2
50
-
51
-
52
- const acknowledgeWithCode = async (authenticationData, {
53
- clientId,
54
- redirectURI,
55
- scope
56
- }, additionalParameters) => {
57
- const code = await oAuth2Code.create({ ...authenticationData,
58
- applicationId: clientId,
59
- scope
60
- }, redirectURI, additionalParameters);
55
+ log('debug', '👫 - OAuth2CodeGranter Service Initialized!');
61
56
  return {
62
- applicationId: clientId,
63
- redirectURI,
64
- scope,
65
- code
57
+ type: CODE_GRANTER_TYPE,
58
+ authorizer: {
59
+ responseType: 'code',
60
+ authorize: authorizeWithCode,
61
+ },
62
+ acknowledger: {
63
+ acknowledgmentType: 'code',
64
+ acknowledge: acknowledgeWithCode,
65
+ },
66
+ authenticator: {
67
+ grantType: 'authorization_code',
68
+ authenticate: authenticateWithCode,
69
+ },
66
70
  };
67
- };
68
-
69
- const authenticateWithCode = async ({
70
- code,
71
- clientId,
72
- redirectURI
73
- }, authenticationData) => {
74
- // The client must be authenticated (for now, see below)
75
- if (!authenticationData) {
76
- throw new _yerror.default('E_UNAUTHORIZED');
77
- } // This check is not really necessary atm but it acts
78
- // as a reminder that this grant type could be used
79
- // without authenticating the client. In this
80
- // scenario, the authenticationData should be deducted
81
- // from the clientId and the code given in parameters
82
- // See https://tools.ietf.org/html/rfc6749#section-4.1.3
83
-
84
-
85
- if (clientId && clientId !== authenticationData.applicationId) {
86
- throw new _yerror.default('E_UNAUTHORIZED', clientId, authenticationData.applicationId);
87
- }
88
-
89
- await checkApplication({
90
- applicationId: authenticationData.applicationId,
91
- type: CODE_GRANTER_TYPE,
92
- scope: ''
93
- });
94
- const newAuthenticationData = await oAuth2Code.check(authenticationData, code, redirectURI);
95
- return newAuthenticationData;
96
- };
97
-
98
- log('debug', '👫 - OAuth2CodeGranter Service Initialized!');
99
- return {
100
- type: CODE_GRANTER_TYPE,
101
- authorizer: {
102
- responseType: 'code',
103
- authorize: authorizeWithCode
104
- },
105
- acknowledger: {
106
- acknowledgmentType: 'code',
107
- acknowledge: acknowledgeWithCode
108
- },
109
- authenticator: {
110
- grantType: 'authorization_code',
111
- authenticate: authenticateWithCode
112
- }
113
- };
114
71
  }
115
72
  //# sourceMappingURL=oAuth2CodeGranter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oAuth2CodeGranter.js","names":["CODE_GRANTER_TYPE","autoService","initOAuth2CodeGranter","oAuth2Code","checkApplication","log","noop","authorizeWithCode","clientId","redirectURI","scope","finalRedirectURI","applicationId","type","acknowledgeWithCode","authenticationData","additionalParameters","code","create","authenticateWithCode","YError","newAuthenticationData","check","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate"],"sources":["../../src/services/oAuth2CodeGranter.ts"],"sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n OAuth2CodeService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const CODE_GRANTER_TYPE = 'code';\n\nexport type OAuth2CodeGranterDependencies = {\n oAuth2Code: OAuth2CodeService;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2CodeGranterParameters = {\n code: string;\n redirectURI: string;\n clientId: string;\n};\nexport type OAuth2CodeGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2CodeGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2CodeGranter);\n\n// Authorization Code Grant\n// https://tools.ietf.org/html/rfc6749#section-4.1\nasync function initOAuth2CodeGranter({\n oAuth2Code,\n checkApplication,\n log = noop,\n}: OAuth2CodeGranterDependencies): Promise<OAuth2CodeGranterService> {\n const authorizeWithCode: NonNullable<\n OAuth2CodeGranterService['authorizer']\n >['authorize'] = async ({ clientId, redirectURI, scope = '' }) => {\n const { redirectURI: finalRedirectURI } = await checkApplication({\n applicationId: clientId,\n type: CODE_GRANTER_TYPE,\n redirectURI,\n scope,\n });\n\n return {\n applicationId: clientId,\n redirectURI: finalRedirectURI,\n scope,\n };\n };\n\n // Authorization Code Response:\n // https://tools.ietf.org/html/rfc6749#section-4.1.2\n const acknowledgeWithCode: NonNullable<\n OAuth2CodeGranterService['acknowledger']\n >['acknowledge'] = async (\n authenticationData,\n { clientId, redirectURI, scope },\n additionalParameters,\n ) => {\n const code = await oAuth2Code.create(\n { ...authenticationData, applicationId: clientId, scope },\n redirectURI,\n additionalParameters,\n );\n\n return {\n applicationId: clientId,\n redirectURI,\n scope,\n code,\n };\n };\n\n const authenticateWithCode: NonNullable<\n OAuth2CodeGranterService['authenticator']\n >['authenticate'] = async (\n { code, clientId, redirectURI },\n authenticationData,\n ) => {\n // The client must be authenticated (for now, see below)\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // This check is not really necessary atm but it acts\n // as a reminder that this grant type could be used\n // without authenticating the client. In this\n // scenario, the authenticationData should be deducted\n // from the clientId and the code given in parameters\n // See https://tools.ietf.org/html/rfc6749#section-4.1.3\n if (clientId && clientId !== authenticationData.applicationId) {\n throw new YError(\n 'E_UNAUTHORIZED',\n clientId,\n authenticationData.applicationId,\n );\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: CODE_GRANTER_TYPE,\n scope: '',\n });\n\n const newAuthenticationData = await oAuth2Code.check(\n authenticationData,\n code,\n redirectURI,\n );\n\n return newAuthenticationData;\n };\n\n log('debug', '👫 - OAuth2CodeGranter Service Initialized!');\n\n return {\n type: CODE_GRANTER_TYPE,\n authorizer: {\n responseType: 'code',\n authorize: authorizeWithCode,\n },\n acknowledger: {\n acknowledgmentType: 'code',\n acknowledge: acknowledgeWithCode,\n },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: authenticateWithCode,\n },\n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H;QAED,MAAM,gBAAgB,CAAC;YACrB,aAAa,EAAE,kBAAkB,CAAC,aAAa;YAC/C,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;QAEH,MAAM,qBAAqB,GAAG,MAAM,UAAU,CAAC,KAAK,CAClD,kBAAkB,EAClB,IAAI,EACJ,WAAW,CACZ,CAAC;QAEF,OAAO,qBAAqB,CAAC;IAC/B,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,6CAA6C,CAAC,CAAC;IAE5D,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE;YACV,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,iBAAiB;SAC7B;QACD,YAAY,EAAE;YACZ,kBAAkB,EAAE,MAAM;YAC1B,WAAW,EAAE,mBAAmB;SACjC;QACD,aAAa,EAAE;YACb,SAAS,EAAE,oBAAoB;YAC/B,YAAY,EAAE,oBAAoB;SACnC;KACF,CAAC;AACJ,CAAC"}
@@ -1,64 +1,62 @@
1
- "use strict";
2
-
3
- var _oAuth2CodeGranter = _interopRequireDefault(require("./oAuth2CodeGranter"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
1
+ import { jest } from '@jest/globals';
2
+ import initOAuth2CodeGranter from './oAuth2CodeGranter.js';
7
3
  describe('OAuth2CodeGranter', () => {
8
- const oAuth2Code = {
9
- create: jest.fn(),
10
- check: jest.fn()
11
- };
12
- const checkApplication = jest.fn();
13
- const log = jest.fn();
14
- beforeEach(() => {
15
- oAuth2Code.create.mockReset();
16
- oAuth2Code.check.mockReset();
17
- checkApplication.mockReset();
18
- log.mockReset();
19
- });
20
- it('should work with a complete valid flow', async () => {
21
- var _oAuth2CodeGranter$au, _oAuth2CodeGranter$ac, _oAuth2CodeGranter$au2;
22
-
23
- const oAuth2CodeGranter = await (0, _oAuth2CodeGranter.default)({
24
- checkApplication,
25
- oAuth2Code,
26
- log
4
+ const oAuth2Code = {
5
+ create: jest.fn(),
6
+ check: jest.fn(),
7
+ };
8
+ const checkApplication = jest.fn();
9
+ const log = jest.fn();
10
+ beforeEach(() => {
11
+ oAuth2Code.create.mockReset();
12
+ oAuth2Code.check.mockReset();
13
+ checkApplication.mockReset();
14
+ log.mockReset();
27
15
  });
28
- checkApplication.mockResolvedValue({
29
- redirectURI: 'https://www.example.com'
30
- });
31
- oAuth2Code.create.mockResolvedValueOnce('yolo');
32
- oAuth2Code.check.mockResolvedValueOnce({
33
- applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
34
- scope: 'user'
35
- });
36
- const authorizerResult = await ((_oAuth2CodeGranter$au = oAuth2CodeGranter.authorizer) === null || _oAuth2CodeGranter$au === void 0 ? void 0 : _oAuth2CodeGranter$au.authorize({
37
- clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
38
- redirectURI: 'https://www.example.com/oauth2/code',
39
- scope: 'user'
40
- }));
41
- const acknowledgerResult = await ((_oAuth2CodeGranter$ac = oAuth2CodeGranter.acknowledger) === null || _oAuth2CodeGranter$ac === void 0 ? void 0 : _oAuth2CodeGranter$ac.acknowledge({
42
- applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
43
- scope: 'user, admin'
44
- }, {
45
- clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
46
- redirectURI: 'https://www.example.com/oauth2/code',
47
- scope: 'user'
48
- }, {}));
49
- const authenticatorResult = await ((_oAuth2CodeGranter$au2 = oAuth2CodeGranter.authenticator) === null || _oAuth2CodeGranter$au2 === void 0 ? void 0 : _oAuth2CodeGranter$au2.authenticate({
50
- clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
51
- redirectURI: 'https://www.example.com/oauth2/code',
52
- code: 'yolo'
53
- }, {
54
- applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
55
- scope: 'user'
56
- }));
57
- expect({
58
- authorizerResult,
59
- acknowledgerResult,
60
- authenticatorResult
61
- }).toMatchInlineSnapshot(`
16
+ it('should work with a complete valid flow', async () => {
17
+ const oAuth2CodeGranter = await initOAuth2CodeGranter({
18
+ checkApplication,
19
+ oAuth2Code,
20
+ log,
21
+ });
22
+ checkApplication.mockResolvedValue({
23
+ redirectURI: 'https://www.example.com',
24
+ type: 'a_type',
25
+ scope: 'a_scope',
26
+ applicationId: 'abbacaca-abba-caca-abba-cacaabbac0c0',
27
+ });
28
+ oAuth2Code.create.mockResolvedValueOnce('yolo');
29
+ oAuth2Code.check.mockResolvedValueOnce({
30
+ redirectURI: 'https://www.example2.com',
31
+ applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
32
+ scope: 'user',
33
+ });
34
+ const authorizerResult = await oAuth2CodeGranter.authorizer?.authorize({
35
+ clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
36
+ redirectURI: 'https://www.example.com/oauth2/code',
37
+ scope: 'user',
38
+ });
39
+ const acknowledgerResult = await oAuth2CodeGranter.acknowledger?.acknowledge({
40
+ applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
41
+ scope: 'user, admin',
42
+ }, {
43
+ clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
44
+ redirectURI: 'https://www.example.com/oauth2/code',
45
+ scope: 'user',
46
+ }, {});
47
+ const authenticatorResult = await oAuth2CodeGranter.authenticator?.authenticate({
48
+ clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
49
+ redirectURI: 'https://www.example.com/oauth2/code',
50
+ code: 'yolo',
51
+ }, {
52
+ applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
53
+ scope: 'user',
54
+ });
55
+ expect({
56
+ authorizerResult,
57
+ acknowledgerResult,
58
+ authenticatorResult,
59
+ }).toMatchInlineSnapshot(`
62
60
  Object {
63
61
  "acknowledgerResult": Object {
64
62
  "applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
@@ -68,6 +66,7 @@ describe('OAuth2CodeGranter', () => {
68
66
  },
69
67
  "authenticatorResult": Object {
70
68
  "applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
69
+ "redirectURI": "https://www.example2.com",
71
70
  "scope": "user",
72
71
  },
73
72
  "authorizerResult": Object {
@@ -77,12 +76,12 @@ describe('OAuth2CodeGranter', () => {
77
76
  },
78
77
  }
79
78
  `);
80
- expect({
81
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
82
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
83
- checkApplicationCalls: checkApplication.mock.calls,
84
- logCalls: log.mock.calls
85
- }).toMatchSnapshot();
86
- });
79
+ expect({
80
+ oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
81
+ oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
82
+ checkApplicationCalls: checkApplication.mock.calls,
83
+ logCalls: log.mock.calls,
84
+ }).toMatchSnapshot();
85
+ });
87
86
  });
88
87
  //# sourceMappingURL=oAuth2CodeGranter.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oAuth2CodeGranter.test.js","names":["describe","oAuth2Code","create","jest","fn","check","checkApplication","log","beforeEach","mockReset","it","oAuth2CodeGranter","initOAuth2CodeGranter","mockResolvedValue","redirectURI","mockResolvedValueOnce","applicationId","scope","authorizerResult","authorizer","authorize","clientId","acknowledgerResult","acknowledger","acknowledge","authenticatorResult","authenticator","authenticate","code","expect","toMatchInlineSnapshot","oAuth2CodeCreateCalls","mock","calls","oAuth2CodeCheckCalls","checkApplicationCalls","logCalls","toMatchSnapshot"],"sources":["../../src/services/oAuth2CodeGranter.test.ts"],"sourcesContent":["import initOAuth2CodeGranter from './oAuth2CodeGranter';\n\ndescribe('OAuth2CodeGranter', () => {\n const oAuth2Code = {\n create: jest.fn(),\n check: jest.fn(),\n };\n const checkApplication = jest.fn();\n const log = jest.fn();\n\n beforeEach(() => {\n oAuth2Code.create.mockReset();\n oAuth2Code.check.mockReset();\n checkApplication.mockReset();\n log.mockReset();\n });\n\n it('should work with a complete valid flow', async () => {\n const oAuth2CodeGranter = await initOAuth2CodeGranter({\n checkApplication,\n oAuth2Code,\n log,\n });\n\n checkApplication.mockResolvedValue({\n redirectURI: 'https://www.example.com',\n });\n oAuth2Code.create.mockResolvedValueOnce('yolo');\n oAuth2Code.check.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n });\n\n const authorizerResult = await oAuth2CodeGranter.authorizer?.authorize({\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n scope: 'user',\n });\n const acknowledgerResult =\n await oAuth2CodeGranter.acknowledger?.acknowledge(\n {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user, admin',\n },\n {\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n scope: 'user',\n },\n {},\n );\n const authenticatorResult =\n await oAuth2CodeGranter.authenticator?.authenticate(\n {\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n code: 'yolo',\n },\n {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n );\n\n expect({\n authorizerResult,\n acknowledgerResult,\n authenticatorResult,\n }).toMatchInlineSnapshot(`\n Object {\n \"acknowledgerResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"code\": \"yolo\",\n \"redirectURI\": \"https://www.example.com/oauth2/code\",\n \"scope\": \"user\",\n },\n \"authenticatorResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"scope\": \"user\",\n },\n \"authorizerResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"redirectURI\": \"https://www.example.com\",\n \"scope\": \"user\",\n },\n }\n `);\n expect({\n oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,\n oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,\n checkApplicationCalls: checkApplication.m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E;IAFT,CADI,EAKJ;MACEI,QAAQ,EAAE,sCADZ;MAEEP,WAAW,EAAE,qCAFf;MAGEG,KAAK,EAAE;IAHT,CALI,EAUJ,EAVI,CAAN,CADF;IAaA,MAAMQ,mBAAmB,GACvB,iCAAMd,iBAAiB,CAACe,aAAxB,2DAAM,uBAAiCC,YAAjC,CACJ;MACEN,QAAQ,EAAE,sCADZ;MAEEP,WAAW,EAAE,qCAFf;MAGEc,IAAI,EAAE;IAHR,CADI,EAMJ;MACEZ,aAAa,EAAE,sCADjB;MAEEC,KAAK,EAAE;IAFT,CANI,CAAN,CADF;IAaAY,MAAM,CAAC;MACLX,gBADK;MAELI,kBAFK;MAGLG;IAHK,CAAD,CAAN,CAIGK,qBAJH,CAI0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAtBI;IAuBAD,MAAM,CAAC;MACLE,qBAAqB,EAAE9B,UAAU,CAACC,MAAX,CAAkB8B,IAAlB,CAAuBC,KADzC;MAELC,oBAAoB,EAAEjC,UAAU,CAACI,KAAX,CAAiB2B,IAAjB,CAAsBC,KAFvC;MAGLE,qBAAqB,EAAE7B,gBAAgB,CAAC0B,IAAjB,CAAsBC,KAHxC;MAILG,QAAQ,EAAE7B,GAAG,CAACyB,IAAJ,CAASC;IAJd,CAAD,CAAN,CAKGI,eALH;EAMD,CA5EC,CAAF;AA6ED,CA5FO,CAAR"}
1
+ {"version":3,"file":"oAuth2CodeGranter.test.js","sourceRoot":"","sources":["../../src/services/oAuth2CodeGranter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,qBAAqB,MAAM,wBAAwB,CAAC;AAM3D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,MAAM,UAAU,GAAG;QACjB,MAAM,EACJ,IAAI,CAAC,EAAE,EAKJ;QACL,KAAK,EACH,IAAI,C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