@whook/oauth2 8.5.1 → 10.0.0

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 (133) hide show
  1. package/README.md +106 -70
  2. package/dist/handlers/getOAuth2Authorize.d.ts +8 -6
  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 +3 -3
  8. package/dist/handlers/postAuthLogin.js +83 -120
  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 +4 -4
  18. package/dist/handlers/postAuthRefresh.js +93 -131
  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 +11 -8
  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 +4 -4
  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 -620
  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 -64
  49. package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
  50. package/dist/services/oAuth2Granters.d.ts +22 -19
  51. package/dist/services/oAuth2Granters.js +131 -138
  52. package/dist/services/oAuth2Granters.js.map +1 -1
  53. package/dist/services/oAuth2PasswordGranter.d.ts +1 -1
  54. package/dist/services/oAuth2PasswordGranter.js +27 -52
  55. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  56. package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -1
  57. package/dist/services/oAuth2RefreshTokenGranter.js +34 -58
  58. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  59. package/dist/services/oAuth2TokenGranter.d.ts +1 -1
  60. package/dist/services/oAuth2TokenGranter.js +50 -86
  61. package/dist/services/oAuth2TokenGranter.js.map +1 -1
  62. package/package.json +54 -96
  63. package/src/__snapshots__/index.test.ts.snap +23 -22
  64. package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +1 -1
  65. package/src/handlers/getOAuth2Authorize.test.ts +49 -13
  66. package/src/handlers/getOAuth2Authorize.ts +17 -16
  67. package/src/handlers/postAuthLogin.test.ts +9 -5
  68. package/src/handlers/postAuthLogin.ts +8 -7
  69. package/src/handlers/postAuthLogout.test.ts +8 -4
  70. package/src/handlers/postAuthLogout.ts +2 -2
  71. package/src/handlers/postAuthRefresh.test.ts +10 -6
  72. package/src/handlers/postAuthRefresh.ts +8 -7
  73. package/src/handlers/postOAuth2Acknowledge.test.ts +83 -35
  74. package/src/handlers/postOAuth2Acknowledge.ts +48 -30
  75. package/src/handlers/postOAuth2Token.test.ts +79 -19
  76. package/src/handlers/postOAuth2Token.ts +7 -7
  77. package/src/index.test.ts +116 -72
  78. package/src/index.ts +21 -19
  79. package/src/services/authCookies.test.ts +2 -2
  80. package/src/services/authCookies.ts +10 -5
  81. package/src/services/oAuth2ClientCredentialsGranter.ts +28 -24
  82. package/src/services/oAuth2CodeGranter.test.ts +42 -18
  83. package/src/services/oAuth2CodeGranter.ts +68 -62
  84. package/src/services/oAuth2Granters.ts +59 -29
  85. package/src/services/oAuth2PasswordGranter.ts +25 -24
  86. package/src/services/oAuth2RefreshTokenGranter.ts +30 -26
  87. package/src/services/oAuth2TokenGranter.ts +45 -43
  88. package/dist/handlers/getOAuth2Authorize.mjs +0 -160
  89. package/dist/handlers/getOAuth2Authorize.mjs.map +0 -1
  90. package/dist/handlers/getOAuth2Authorize.test.mjs +0 -114
  91. package/dist/handlers/getOAuth2Authorize.test.mjs.map +0 -1
  92. package/dist/handlers/postAuthLogin.mjs +0 -108
  93. package/dist/handlers/postAuthLogin.mjs.map +0 -1
  94. package/dist/handlers/postAuthLogin.test.mjs +0 -85
  95. package/dist/handlers/postAuthLogin.test.mjs.map +0 -1
  96. package/dist/handlers/postAuthLogout.mjs +0 -33
  97. package/dist/handlers/postAuthLogout.mjs.map +0 -1
  98. package/dist/handlers/postAuthLogout.test.mjs +0 -30
  99. package/dist/handlers/postAuthLogout.test.mjs.map +0 -1
  100. package/dist/handlers/postAuthRefresh.mjs +0 -121
  101. package/dist/handlers/postAuthRefresh.mjs.map +0 -1
  102. package/dist/handlers/postAuthRefresh.test.mjs +0 -94
  103. package/dist/handlers/postAuthRefresh.test.mjs.map +0 -1
  104. package/dist/handlers/postOAuth2Acknowledge.mjs +0 -150
  105. package/dist/handlers/postOAuth2Acknowledge.mjs.map +0 -1
  106. package/dist/handlers/postOAuth2Acknowledge.test.mjs +0 -140
  107. package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +0 -1
  108. package/dist/handlers/postOAuth2Token.mjs +0 -231
  109. package/dist/handlers/postOAuth2Token.mjs.map +0 -1
  110. package/dist/handlers/postOAuth2Token.test.mjs +0 -160
  111. package/dist/handlers/postOAuth2Token.test.mjs.map +0 -1
  112. package/dist/index.mjs +0 -15
  113. package/dist/index.mjs.map +0 -1
  114. package/dist/index.test.mjs +0 -748
  115. package/dist/index.test.mjs.map +0 -1
  116. package/dist/services/authCookies.mjs +0 -58
  117. package/dist/services/authCookies.mjs.map +0 -1
  118. package/dist/services/authCookies.test.mjs +0 -77
  119. package/dist/services/authCookies.test.mjs.map +0 -1
  120. package/dist/services/oAuth2ClientCredentialsGranter.mjs +0 -41
  121. package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +0 -1
  122. package/dist/services/oAuth2CodeGranter.mjs +0 -98
  123. package/dist/services/oAuth2CodeGranter.mjs.map +0 -1
  124. package/dist/services/oAuth2CodeGranter.test.mjs +0 -81
  125. package/dist/services/oAuth2CodeGranter.test.mjs.map +0 -1
  126. package/dist/services/oAuth2Granters.mjs +0 -127
  127. package/dist/services/oAuth2Granters.mjs.map +0 -1
  128. package/dist/services/oAuth2PasswordGranter.mjs +0 -40
  129. package/dist/services/oAuth2PasswordGranter.mjs.map +0 -1
  130. package/dist/services/oAuth2RefreshTokenGranter.mjs +0 -47
  131. package/dist/services/oAuth2RefreshTokenGranter.mjs.map +0 -1
  132. package/dist/services/oAuth2TokenGranter.mjs +0 -78
  133. package/dist/services/oAuth2TokenGranter.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postAuthLogin.test.ts"],"names":["describe","test","authCookies","build","jest","fn","postOAuth2Token","postAuthLogin","ROOT_AUTHENTICATION_DATA","scope","applicationId","mockReturnValueOnce","mockResolvedValueOnce","status","body","access_token","expiration_date","expires_in","token_type","response","username","password","remember","expect","authCookiesBuildCalls","mock","calls","postOAuth2TokenCalls","toMatchInlineSnapshot"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,eAAD,EAAkB,MAAM;AAC9BC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL;AADW,KAApB;AAGA,UAAMC,eAAe,GAAGF,IAAI,CAACC,EAAL,EAAxB;AACA,UAAME,aAAa,GAAG,MAAM,4BAAkB;AAC5CC,MAAAA,wBAAwB,EAAE;AACxBC,QAAAA,KAAK,EAAE,MADiB;AAExBC,QAAAA,aAAa,EAAE;AAFS,OADkB;AAK5CR,MAAAA,WAL4C;AAM5CI,MAAAA;AAN4C,KAAlB,CAA5B;AASAJ,IAAAA,WAAW,CAACC,KAAZ,CAAkBQ,mBAAlB,CAAsC,mBAAtC;AACAL,IAAAA,eAAe,CAACM,qBAAhB,CAAsC;AACpCC,MAAAA,MAAM,EAAE,GAD4B;AAEpCC,MAAAA,IAAI,EAAE;AACJC,QAAAA,YAAY,EAAE,iBADV;AAEJC,QAAAA,eAAe,EAAE,sBAFb;AAGJC,QAAAA,UAAU,EAAE,IAHR;AAIJC,QAAAA,UAAU,EAAE;AAJR;AAF8B,KAAtC;AAUA,UAAMC,QAAQ,GAAG,MAAMZ,aAAa,CAAC;AACnCO,MAAAA,IAAI,EAAE;AACJM,QAAAA,QAAQ,EAAE,YADN;AAEJC,QAAAA,QAAQ,EAAE,YAFN;AAGJC,QAAAA,QAAQ,EAAE,KAHN;AAIJb,QAAAA,KAAK,EAAE;AAJH;AAD6B,KAAD,CAApC;AASAc,IAAAA,MAAM,CAAC;AACLJ,MAAAA,QADK;AAELK,MAAAA,qBAAqB,EAAEtB,WAAW,CAACC,KAAZ,CAAkBsB,IAAlB,CAAuBC,KAFzC;AAGLC,MAAAA,oBAAoB,EAAErB,eAAe,CAACmB,IAAhB,CAAqBC;AAHtC,KAAD,CAAN,CAIGE,qBAJH,CAI0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAhDI;AAiDD,GAnFG,CAAJ;AAoFD,CArFO,CAAR","sourcesContent":["import initPostAuthLogin from './postAuthLogin';\n\ndescribe('postAuthLogin', () => {\n test('should work', async () => {\n const authCookies = {\n build: jest.fn(),\n };\n const postOAuth2Token = jest.fn();\n const postAuthLogin = await initPostAuthLogin({\n ROOT_AUTHENTICATION_DATA: {\n scope: 'user',\n applicationId: 'root_app_id',\n },\n authCookies,\n postOAuth2Token,\n });\n\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n postOAuth2Token.mockResolvedValueOnce({\n status: 200,\n body: {\n access_token: 'an_access_token',\n expiration_date: '2020-02-02T20:22:02Z',\n expires_in: 3600,\n token_type: 'bearer',\n },\n });\n\n const response = await postAuthLogin({\n body: {\n username: 'a_username',\n password: 'a_password',\n remember: false,\n scope: 'user',\n },\n });\n\n expect({\n response,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n postOAuth2TokenCalls: postOAuth2Token.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [\n Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n Object {\n \"session\": true,\n },\n ],\n ],\n \"postOAuth2TokenCalls\": Array [\n Array [\n Object {\n \"authenticationData\": Object {\n \"applicationId\": \"root_app_id\",\n \"scope\": \"user\",\n },\n \"body\": Object {\n \"grant_type\": \"password\",\n \"password\": \"a_password\",\n \"scope\": \"user\",\n \"username\": \"a_username\",\n },\n },\n ],\n ],\n \"response\": Object {\n \"body\": Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 200,\n },\n }\n `);\n });\n});\n"],"file":"postAuthLogin.test.js"}
1
+ {"version":3,"file":"postAuthLogin.test.js","sourceRoot":"","sources":["../../src/handlers/postAuthLogin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AAGnD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,WAAW,GAAG;YAClB,KAAK,EAAE,IAAI,CAAC,EAAE,EAA+B;SAC9C,CAAC;QACF,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,EAAO,CAAC;QACvC,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC;YAC5C,wBAAwB,EAAE;gBACxB,KAAK,EAAE,MAAM;gBACb,aAAa,EAAE,aAAa;aAC7B;YACD,WAAW;YACX,eAAe;SAChB,CAAC,CAAC;QAEH,WAAW,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7D,eAAe,CAAC,qBAAqB,CAAC;YACpC,MAAM,EAAE,GAAG;YACX,IAAI,EAAE;gBACJ,YAAY,EAAE,iBAAiB;gBAC/B,eAAe,EAAE,sBAAsB;gBACvC,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,QAAQ;aACrB;SACF,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC;YACnC,IAAI,EAAE;gBACJ,QAAQ,EAAE,YAAY;gBACtB,QAAQ,EAAE,YAAY;gBACtB,QAAQ,EAAE,KAAK;gBACf,KAAK,EAAE,MAAM;aACd;SACF,CAAC,CAAC;QAEH,MAAM,CAAC;YACL,QAAQ;YACR,qBAAqB,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;YACnD,oBAAoB,EAAE,eAAe,CAAC,IAAI,CAAC,KAAK;SACjD,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8CxB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { WhookAPIHandlerDefinition } from '@whook/whook';
2
- import type { AuthCookiesService } from '../services/authCookies';
2
+ import type { AuthCookiesService } from '../services/authCookies.js';
3
3
  export declare const definition: WhookAPIHandlerDefinition;
4
4
  declare const _default: import("knifecycle").ServiceInitializer<{
5
5
  authCookies: Pick<AuthCookiesService, "build">;
@@ -1,46 +1,30 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.definition = exports.default = void 0;
7
-
8
- var _knifecycle = require("knifecycle");
9
-
10
- var _authCookies = require("../services/authCookies");
11
-
12
- const definition = {
13
- method: 'post',
14
- path: `${_authCookies.AUTH_API_PREFIX}/logout`,
15
- operation: {
16
- operationId: 'postAuthLogout',
17
- summary: 'Logs a user out',
18
- tags: ['auth'],
19
- 'x-whook': {
20
- disabled: true
1
+ import { autoHandler } from 'knifecycle';
2
+ import { AUTH_API_PREFIX } from '../services/authCookies.js';
3
+ export const definition = {
4
+ method: 'post',
5
+ path: `${AUTH_API_PREFIX}/logout`,
6
+ operation: {
7
+ operationId: 'postAuthLogout',
8
+ summary: 'Logs a user out',
9
+ tags: ['auth'],
10
+ 'x-whook': {
11
+ disabled: true,
12
+ },
13
+ parameters: [],
14
+ responses: {
15
+ 204: {
16
+ description: 'Successfuly logged out!',
17
+ },
18
+ },
21
19
  },
22
- parameters: [],
23
- responses: {
24
- 204: {
25
- description: 'Successfuly logged out!'
26
- }
27
- }
28
- }
29
20
  };
30
- exports.definition = definition;
31
-
32
- var _default = (0, _knifecycle.handler)(postAuthLogout, "postAuthLogout", ["authCookies"]);
33
-
34
- exports.default = _default;
35
-
36
- async function postAuthLogout({
37
- authCookies
38
- }) {
39
- return {
40
- status: 204,
41
- headers: {
42
- 'Set-Cookie': authCookies.build()
43
- }
44
- };
21
+ export default autoHandler(postAuthLogout);
22
+ async function postAuthLogout({ authCookies, }) {
23
+ return {
24
+ status: 204,
25
+ headers: {
26
+ 'Set-Cookie': authCookies.build(),
27
+ },
28
+ };
45
29
  }
46
30
  //# sourceMappingURL=postAuthLogout.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postAuthLogout.ts"],"names":["definition","method","path","AUTH_API_PREFIX","operation","operationId","summary","tags","disabled","parameters","responses","description","postAuthLogout","authCookies","status","headers","build"],"mappings":";;;;;;;AAAA;;AACA;;AAIO,MAAMA,UAAqC,GAAG;AACnDC,EAAAA,MAAM,EAAE,MAD2C;AAEnDC,EAAAA,IAAI,EAAG,GAAEC,4BAAgB,SAF0B;AAGnDC,EAAAA,SAAS,EAAE;AACTC,IAAAA,WAAW,EAAE,gBADJ;AAETC,IAAAA,OAAO,EAAE,iBAFA;AAGTC,IAAAA,IAAI,EAAE,CAAC,MAAD,CAHG;AAIT,eAAW;AACTC,MAAAA,QAAQ,EAAE;AADD,KAJF;AAOTC,IAAAA,UAAU,EAAE,EAPH;AAQTC,IAAAA,SAAS,EAAE;AACT,WAAK;AACHC,QAAAA,WAAW,EAAE;AADV;AADI;AARF;AAHwC,CAA9C;;;eAmBQ,yBAAYC,cAAZ,oC;;;;AAEf,eAAeA,cAAf,CAA8B;AAC5BC,EAAAA;AAD4B,CAA9B,EAIG;AACD,SAAO;AACLC,IAAAA,MAAM,EAAE,GADH;AAELC,IAAAA,OAAO,EAAE;AACP,oBAAcF,WAAW,CAACG,KAAZ;AADP;AAFJ,GAAP;AAMD","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type { WhookAPIHandlerDefinition } from '@whook/whook';\nimport type { AuthCookiesService } from '../services/authCookies';\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/logout`,\n operation: {\n operationId: 'postAuthLogout',\n summary: 'Logs a user out',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [],\n responses: {\n 204: {\n description: 'Successfuly logged out!',\n },\n },\n },\n};\n\nexport default autoHandler(postAuthLogout);\n\nasync function postAuthLogout({\n authCookies,\n}: {\n authCookies: Pick<AuthCookiesService, 'build'>;\n}) {\n return {\n status: 204,\n headers: {\n 'Set-Cookie': authCookies.build(),\n },\n };\n}\n"],"file":"postAuthLogout.js"}
1
+ {"version":3,"file":"postAuthLogout.js","sourceRoot":"","sources":["../../src/handlers/postAuthLogout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAI7D,MAAM,CAAC,MAAM,UAAU,GAA8B;IACnD,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,GAAG,eAAe,SAAS;IACjC,SAAS,EAAE;QACT,WAAW,EAAE,gBAAgB;QAC7B,OAAO,EAAE,iBAAiB;QAC1B,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,SAAS,EAAE;YACT,QAAQ,EAAE,IAAI;SACf;QACD,UAAU,EAAE,EAAE;QACd,SAAS,EAAE;YACT,GAAG,EAAE;gBACH,WAAW,EAAE,yBAAyB;aACvC;SACF;KACF;CACF,CAAC;AAEF,eAAe,WAAW,CAAC,cAAc,CAAC,CAAC;AAE3C,KAAK,UAAU,cAAc,CAAC,EAC5B,WAAW,GAGZ;IACC,OAAO;QACL,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACP,YAAY,EAAE,WAAW,CAAC,KAAK,EAAE;SAClC;KACF,CAAC;AACJ,CAAC"}
@@ -1,35 +1,33 @@
1
- "use strict";
2
-
3
- var _postAuthLogout = _interopRequireDefault(require("./postAuthLogout"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
1
+ import { jest } from '@jest/globals';
2
+ import initPostAuthLogout from './postAuthLogout.js';
7
3
  describe('postAuthLogout', () => {
8
- test('should work', async () => {
9
- const authCookies = {
10
- build: jest.fn()
11
- };
12
- const postAuthLogout = await (0, _postAuthLogout.default)({
13
- authCookies
14
- });
15
- authCookies.build.mockReturnValueOnce('the_build_cookies');
16
- const response = await postAuthLogout({});
17
- expect({
18
- response,
19
- authCookiesBuildCalls: authCookies.build.mock.calls
20
- }).toMatchInlineSnapshot(`
4
+ test('should work', async () => {
5
+ const authCookies = {
6
+ build: jest.fn(),
7
+ };
8
+ const postAuthLogout = await initPostAuthLogout({
9
+ authCookies,
10
+ });
11
+ authCookies.build.mockReturnValueOnce(['the_build_cookies']);
12
+ const response = await postAuthLogout({});
13
+ expect({
14
+ response,
15
+ authCookiesBuildCalls: authCookies.build.mock.calls,
16
+ }).toMatchInlineSnapshot(`
21
17
  Object {
22
18
  "authCookiesBuildCalls": Array [
23
19
  Array [],
24
20
  ],
25
21
  "response": Object {
26
22
  "headers": Object {
27
- "Set-Cookie": "the_build_cookies",
23
+ "Set-Cookie": Array [
24
+ "the_build_cookies",
25
+ ],
28
26
  },
29
27
  "status": 204,
30
28
  },
31
29
  }
32
30
  `);
33
- });
31
+ });
34
32
  });
35
33
  //# sourceMappingURL=postAuthLogout.test.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postAuthLogout.test.ts"],"names":["describe","test","authCookies","build","jest","fn","postAuthLogout","mockReturnValueOnce","response","expect","authCookiesBuildCalls","mock","calls","toMatchInlineSnapshot"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC/BC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL;AADW,KAApB;AAGA,UAAMC,cAAc,GAAG,MAAM,6BAAmB;AAC9CJ,MAAAA;AAD8C,KAAnB,CAA7B;AAIAA,IAAAA,WAAW,CAACC,KAAZ,CAAkBI,mBAAlB,CAAsC,mBAAtC;AAEA,UAAMC,QAAQ,GAAG,MAAMF,cAAc,CAAC,EAAD,CAArC;AAEAG,IAAAA,MAAM,CAAC;AACLD,MAAAA,QADK;AAELE,MAAAA,qBAAqB,EAAER,WAAW,CAACC,KAAZ,CAAkBQ,IAAlB,CAAuBC;AAFzC,KAAD,CAAN,CAGGC,qBAHH,CAG0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAfI;AAgBD,GA5BG,CAAJ;AA6BD,CA9BO,CAAR","sourcesContent":["import initPostAuthLogout from './postAuthLogout';\n\ndescribe('postAuthLogout', () => {\n test('should work', async () => {\n const authCookies = {\n build: jest.fn(),\n };\n const postAuthLogout = await initPostAuthLogout({\n authCookies,\n });\n\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n\n const response = await postAuthLogout({});\n\n expect({\n response,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [],\n ],\n \"response\": Object {\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 204,\n },\n }\n `);\n });\n});\n"],"file":"postAuthLogout.test.js"}
1
+ {"version":3,"file":"postAuthLogout.test.js","sourceRoot":"","sources":["../../src/handlers/postAuthLogout.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,kBAAkB,MAAM,qBAAqB,CAAC;AAGrD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,WAAW,GAAG;YAClB,KAAK,EAAE,IAAI,CAAC,EAAE,EAA+B;SAC9C,CAAC;QACF,MAAM,cAAc,GAAG,MAAM,kBAAkB,CAAC;YAC9C,WAAW;SACZ,CAAC,CAAC;QAEH,WAAW,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAE7D,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAE1C,MAAM,CAAC;YACL,QAAQ;YACR,qBAAqB,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;SACpD,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;KAcxB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import type { WhookAPIHandlerDefinition, WhookAPIParameterDefinition } from '@whook/whook';
2
- import type { AuthCookiesService, AuthHandlersConfig } from '../services/authCookies';
2
+ import type { AuthCookiesService, AuthHandlersConfig } from '../services/authCookies.js';
3
3
  import type { BaseAuthenticationData } from '@whook/authorization';
4
4
  export declare const authCookieHeaderParameter: WhookAPIParameterDefinition<string>;
5
5
  export declare const definition: WhookAPIHandlerDefinition;
6
- declare const _default: <AUTHENTICATION_DATA extends BaseAuthenticationData<string, string> = BaseAuthenticationData<string, string>>(dependencies?: AuthHandlersConfig<AUTHENTICATION_DATA> & {
6
+ declare const _default: import("knifecycle").ServiceInitializer<AuthHandlersConfig<BaseAuthenticationData<string, string>> & {
7
7
  authCookies: AuthCookiesService;
8
8
  postOAuth2Token: (parameters: {
9
9
  body: {
@@ -24,12 +24,12 @@ declare const _default: <AUTHENTICATION_DATA extends BaseAuthenticationData<stri
24
24
  refresh_token_expiration_date: string;
25
25
  };
26
26
  }>;
27
- }) => Promise<(parameters: {
27
+ }, (parameters: {
28
28
  body: {
29
29
  scope: string;
30
30
  remember: boolean;
31
31
  };
32
- cookie?: string;
32
+ cookie?: string | undefined;
33
33
  }) => Promise<{
34
34
  headers: {
35
35
  'Set-Cookie': string[];
@@ -1,140 +1,102 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.definition = exports.default = exports.authCookieHeaderParameter = void 0;
7
-
8
- var _knifecycle = require("knifecycle");
9
-
10
- var _yhttperror = _interopRequireDefault(require("yhttperror"));
11
-
12
- var _whook = require("@whook/whook");
13
-
14
- var _authCookies = require("../services/authCookies");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const authCookieHeaderParameter = {
19
- name: 'cookie',
20
- example: 'access_token=an_access_token; refresh_token=a_refresh_token;',
21
- parameter: {
1
+ import { autoHandler } from 'knifecycle';
2
+ import { YHTTPError } from 'yhttperror';
3
+ import { refersTo } from '@whook/whook';
4
+ import { AUTH_API_PREFIX } from '../services/authCookies.js';
5
+ export const authCookieHeaderParameter = {
22
6
  name: 'cookie',
23
- in: 'header',
24
- required: false,
25
- schema: {
26
- type: 'string'
27
- }
28
- }
29
- };
30
- exports.authCookieHeaderParameter = authCookieHeaderParameter;
31
- const definition = {
32
- method: 'post',
33
- path: `${_authCookies.AUTH_API_PREFIX}/refresh`,
34
- operation: {
35
- operationId: 'postAuthRefresh',
36
- summary: 'Refreshs a user auth',
37
- tags: ['auth'],
38
- 'x-whook': {
39
- disabled: true
7
+ example: 'access_token=an_access_token; refresh_token=a_refresh_token;',
8
+ parameter: {
9
+ name: 'cookie',
10
+ in: 'header',
11
+ required: false,
12
+ schema: {
13
+ type: 'string',
14
+ },
40
15
  },
41
- parameters: [(0, _whook.refersTo)(authCookieHeaderParameter)],
42
- requestBody: {
43
- required: true,
44
- content: {
45
- 'application/json': {
46
- schema: {
47
- type: 'object',
48
- required: [],
49
- properties: {
50
- scope: {
51
- type: 'string'
52
- },
53
- remember: {
54
- type: 'boolean'
55
- }
56
- }
57
- }
58
- }
59
- }
60
- },
61
- responses: {
62
- 200: {
63
- description: 'Successfuly refreshed.',
64
- content: {
65
- 'application/json': {
66
- schema: {
67
- type: 'object',
68
- properties: {
69
- access_token: {
70
- type: 'string'
71
- },
72
- expiration_date: {
73
- type: 'string'
16
+ };
17
+ export const definition = {
18
+ method: 'post',
19
+ path: `${AUTH_API_PREFIX}/refresh`,
20
+ operation: {
21
+ operationId: 'postAuthRefresh',
22
+ summary: 'Refreshs a user auth',
23
+ tags: ['auth'],
24
+ 'x-whook': {
25
+ disabled: true,
26
+ },
27
+ parameters: [refersTo(authCookieHeaderParameter)],
28
+ requestBody: {
29
+ required: true,
30
+ content: {
31
+ 'application/json': {
32
+ schema: {
33
+ type: 'object',
34
+ required: [],
35
+ properties: {
36
+ scope: { type: 'string' },
37
+ remember: { type: 'boolean' },
38
+ },
39
+ },
74
40
  },
75
- expires_in: {
76
- type: 'string'
41
+ },
42
+ },
43
+ responses: {
44
+ 200: {
45
+ description: 'Successfuly refreshed.',
46
+ content: {
47
+ 'application/json': {
48
+ schema: {
49
+ type: 'object',
50
+ properties: {
51
+ access_token: { type: 'string' },
52
+ expiration_date: { type: 'string' },
53
+ expires_in: { type: 'string' },
54
+ token_type: { type: 'string' },
55
+ },
56
+ },
57
+ },
77
58
  },
78
- token_type: {
79
- type: 'string'
80
- }
81
- }
82
- }
83
- }
59
+ },
60
+ },
61
+ },
62
+ };
63
+ export default autoHandler(postAuthRefresh);
64
+ async function postAuthRefresh({ ROOT_AUTHENTICATION_DATA, authCookies, postOAuth2Token, }, { body, cookie = '', }) {
65
+ const parsedCookies = authCookies.parse(cookie);
66
+ try {
67
+ if (!parsedCookies.refresh_token) {
68
+ throw new YHTTPError(401, 'E_REFRESH_COOKIE', cookie);
84
69
  }
85
- }
70
+ const response = await postOAuth2Token({
71
+ body: {
72
+ grant_type: 'refresh_token',
73
+ scope: body.scope,
74
+ refresh_token: parsedCookies.refresh_token,
75
+ },
76
+ authenticationData: ROOT_AUTHENTICATION_DATA,
77
+ });
78
+ return {
79
+ ...response,
80
+ headers: {
81
+ ...(response.headers || {}),
82
+ 'Set-Cookie': authCookies.build(response.status === 200 ? response.body : undefined, { session: !body.remember }),
83
+ },
84
+ body: {
85
+ access_token: response.body.access_token,
86
+ expiration_date: response.body.expiration_date,
87
+ expires_in: response.body.expires_in,
88
+ token_type: response.body.token_type,
89
+ },
90
+ };
86
91
  }
87
- }
88
- };
89
- exports.definition = definition;
90
-
91
- var _default = (0, _knifecycle.handler)(postAuthRefresh, "postAuthRefresh", ["ROOT_AUTHENTICATION_DATA", "authCookies", "postOAuth2Token"]);
92
-
93
- exports.default = _default;
94
-
95
- async function postAuthRefresh({
96
- ROOT_AUTHENTICATION_DATA,
97
- authCookies,
98
- postOAuth2Token
99
- }, {
100
- body,
101
- cookie = ''
102
- }) {
103
- const parsedCookies = authCookies.parse(cookie);
104
-
105
- try {
106
- if (!parsedCookies.refresh_token) {
107
- throw new _yhttperror.default(401, 'E_REFRESH_COOKIE', cookie);
92
+ catch (err) {
93
+ const newErr = YHTTPError.wrap(err);
94
+ newErr.headers = {
95
+ ...(err.headers || {}),
96
+ // TODO: Allow string[] in YHTTPError
97
+ 'Set-Cookie': authCookies.build(),
98
+ };
99
+ throw newErr;
108
100
  }
109
-
110
- const response = await postOAuth2Token({
111
- body: {
112
- grant_type: 'refresh_token',
113
- scope: body.scope,
114
- refresh_token: parsedCookies.refresh_token
115
- },
116
- authenticationData: ROOT_AUTHENTICATION_DATA
117
- });
118
- return { ...response,
119
- headers: { ...(response.headers || {}),
120
- 'Set-Cookie': authCookies.build(response.status === 200 ? response.body : undefined, {
121
- session: !body.remember
122
- })
123
- },
124
- body: {
125
- access_token: response.body.access_token,
126
- expiration_date: response.body.expiration_date,
127
- expires_in: response.body.expires_in,
128
- token_type: response.body.token_type
129
- }
130
- };
131
- } catch (err) {
132
- const newErr = _yhttperror.default.wrap(err);
133
-
134
- newErr.headers = { ...(err.headers || {}),
135
- 'Set-Cookie': authCookies.build()
136
- };
137
- throw newErr;
138
- }
139
101
  }
140
102
  //# sourceMappingURL=postAuthRefresh.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postAuthRefresh.ts"],"names":["authCookieHeaderParameter","name","example","parameter","in","required","schema","type","definition","method","path","AUTH_API_PREFIX","operation","operationId","summary","tags","disabled","parameters","requestBody","content","properties","scope","remember","responses","description","access_token","expiration_date","expires_in","token_type","postAuthRefresh","ROOT_AUTHENTICATION_DATA","authCookies","postOAuth2Token","body","cookie","parsedCookies","parse","refresh_token","YHTTPError","response","grant_type","authenticationData","headers","build","status","undefined","session","err","newErr","wrap"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;AAYO,MAAMA,yBAA8D,GAAG;AAC5EC,EAAAA,IAAI,EAAE,QADsE;AAE5EC,EAAAA,OAAO,EAAE,8DAFmE;AAG5EC,EAAAA,SAAS,EAAE;AACTF,IAAAA,IAAI,EAAE,QADG;AAETG,IAAAA,EAAE,EAAE,QAFK;AAGTC,IAAAA,QAAQ,EAAE,KAHD;AAITC,IAAAA,MAAM,EAAE;AACNC,MAAAA,IAAI,EAAE;AADA;AAJC;AAHiE,CAAvE;;AAaA,MAAMC,UAAqC,GAAG;AACnDC,EAAAA,MAAM,EAAE,MAD2C;AAEnDC,EAAAA,IAAI,EAAG,GAAEC,4BAAgB,UAF0B;AAGnDC,EAAAA,SAAS,EAAE;AACTC,IAAAA,WAAW,EAAE,iBADJ;AAETC,IAAAA,OAAO,EAAE,sBAFA;AAGTC,IAAAA,IAAI,EAAE,CAAC,MAAD,CAHG;AAIT,eAAW;AACTC,MAAAA,QAAQ,EAAE;AADD,KAJF;AAOTC,IAAAA,UAAU,EAAE,CAAC,qBAASjB,yBAAT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perror';\nimport { refersTo } from '@whook/whook';\nimport initPostOauth2Token from './postOAuth2Token';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type {\n WhookAPIHandlerDefinition,\n WhookAPIParameterDefinition,\n} from '@whook/whook';\nimport type {\n AuthCookiesService,\n AuthHandlersConfig,\n} from '../services/authCookies';\nimport type { AsyncReturnType } from 'type-fest';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const authCookieHeaderParameter: WhookAPIParameterDefinition<string> = {\n name: 'cookie',\n example: 'access_token=an_access_token; refresh_token=a_refresh_token;',\n parameter: {\n name: 'cookie',\n in: 'header',\n required: false,\n schema: {\n type: 'string',\n },\n },\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/refresh`,\n operation: {\n operationId: 'postAuthRefresh',\n summary: 'Refreshs a user auth',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [refersTo(authCookieHeaderParameter)],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: [],\n properties: {\n scope: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successfuly refreshed.',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n access_token: { type: 'string' },\n expiration_date: { type: 'string' },\n expires_in: { type: 'string' },\n token_type: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postAuthRefresh);\n\nasync function postAuthRefresh<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ROOT_AUTHENTICATION_DATA,\n authCookies,\n postOAuth2Token,\n }: AuthHandlersConfig<AUTHENTICATION_DATA> & {\n authCookies: AuthCookiesService;\n postOAuth2Token: AsyncReturnType<typeof initPostOauth2Token>;\n },\n {\n body,\n cookie = '',\n }: {\n body: {\n scope: string;\n remember: boolean;\n };\n cookie?: string;\n },\n) {\n const parsedCookies = authCookies.parse(cookie);\n\n try {\n if (!parsedCookies.refresh_token) {\n throw new YHTTPError(401, 'E_REFRESH_COOKIE', cookie);\n }\n\n const response = await postOAuth2Token({\n body: {\n grant_type: 'refresh_token',\n scope: body.scope,\n refresh_token: parsedCookies.refresh_token,\n },\n authenticationData: ROOT_AUTHENTICATION_DATA,\n });\n\n return {\n ...response,\n headers: {\n ...(response.headers || {}),\n 'Set-Cookie': authCookies.build(\n response.status === 200 ? response.body : undefined,\n { session: !body.remember },\n ),\n },\n body: {\n access_token: response.body.access_token,\n expiration_date: response.body.expiration_date,\n expires_in: response.body.expires_in,\n token_type: response.body.token_type,\n },\n };\n } catch (err) {\n const newErr = YHTTPError.wrap(err);\n\n newErr.headers = {\n ...(err.headers || {}),\n 'Set-Cookie': authCookies.build(),\n };\n\n throw newErr;\n }\n}\n"],"file":"postAuthRefresh.js"}
1
+ {"version":3,"file":"postAuthRefresh.js","sourceRoot":"","sources":["../../src/handlers/postAuthRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAY7D,MAAM,CAAC,MAAM,yBAAyB,GAAwC;IAC5E,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,8DAA8D;IACvE,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,EAAE,EAAE,QAAQ;QACZ,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;SACf;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAA8B;IACnD,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,GAAG,eAAe,UAAU;IAClC,SAAS,EAAE;QACT,WAAW,EAAE,iBAAiB;QAC9B,OAAO,EAAE,sBAA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,QAAQ,GAAG,MAAM,eAAe,CAAC;YACrC,IAAI,EAAE;gBACJ,UAAU,EAAE,eAAe;gBAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,aAAa,EAAE,aAAa,CAAC,aAAa;aAC3C;YACD,kBAAkB,EAAE,wBAAwB;SAC7C,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE;gBACP,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC;gBAC3B,YAAY,EAAE,WAAW,CAAC,KAAK,CAC7B,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EACnD,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAC5B;aACF;YACD,IAAI,EAAE;gBACJ,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;gBACxC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,eAAe;gBAC9C,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;gBACpC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;aACrC;SACF,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,GAAY,CAAC,CAAC;QAE7C,MAAM,CAAC,OAAO,GAAG;YACf,GAAG,CAAE,GAAkB,CAAC,OAAO,IAAI,EAAE,CAAC;YACtC,qCAAqC;YACrC,YAAY,EAAE,WAAW,CAAC,KAAK,EAAuB;SACvD,CAAC;QAEF,MAAM,MAAM,CAAC;KACd;AACH,CAAC"}
@@ -1,51 +1,47 @@
1
- "use strict";
2
-
3
- var _postAuthRefresh = _interopRequireDefault(require("./postAuthRefresh"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
1
+ import { jest } from '@jest/globals';
2
+ import initPostAuthRefresh from './postAuthRefresh.js';
7
3
  describe('postAuthRefresh', () => {
8
- test('should work', async () => {
9
- const authCookies = {
10
- parse: jest.fn(),
11
- build: jest.fn()
12
- };
13
- const postOAuth2Token = jest.fn();
14
- const postAuthRefresh = await (0, _postAuthRefresh.default)({
15
- ROOT_AUTHENTICATION_DATA: {
16
- scope: 'user',
17
- applicationId: 'root_app_id'
18
- },
19
- authCookies,
20
- postOAuth2Token
21
- });
22
- authCookies.parse.mockReturnValueOnce({
23
- access_token: 'an_access_token',
24
- refresh_token: 'a_refresh_token'
25
- });
26
- authCookies.build.mockReturnValueOnce('the_build_cookies');
27
- postOAuth2Token.mockResolvedValueOnce({
28
- status: 200,
29
- body: {
30
- access_token: 'an_access_token',
31
- expiration_date: '2020-02-02T20:22:02Z',
32
- expires_in: 3600,
33
- token_type: 'bearer'
34
- }
35
- });
36
- const response = await postAuthRefresh({
37
- cookie: 'a_given_cookie',
38
- body: {
39
- remember: false,
40
- scope: 'user'
41
- }
42
- });
43
- expect({
44
- response,
45
- authCookiesParseCalls: authCookies.parse.mock.calls,
46
- authCookiesBuildCalls: authCookies.build.mock.calls,
47
- postOAuth2TokenCalls: postOAuth2Token.mock.calls
48
- }).toMatchInlineSnapshot(`
4
+ test('should work', async () => {
5
+ const authCookies = {
6
+ parse: jest.fn(),
7
+ build: jest.fn(),
8
+ };
9
+ const postOAuth2Token = jest.fn();
10
+ const postAuthRefresh = await initPostAuthRefresh({
11
+ ROOT_AUTHENTICATION_DATA: {
12
+ scope: 'user',
13
+ applicationId: 'root_app_id',
14
+ },
15
+ authCookies,
16
+ postOAuth2Token,
17
+ });
18
+ authCookies.parse.mockReturnValueOnce({
19
+ access_token: 'an_access_token',
20
+ refresh_token: 'a_refresh_token',
21
+ });
22
+ authCookies.build.mockReturnValueOnce(['the_build_cookies']);
23
+ postOAuth2Token.mockResolvedValueOnce({
24
+ status: 200,
25
+ body: {
26
+ access_token: 'an_access_token',
27
+ expiration_date: '2020-02-02T20:22:02Z',
28
+ expires_in: 3600,
29
+ token_type: 'bearer',
30
+ },
31
+ });
32
+ const response = await postAuthRefresh({
33
+ cookie: 'a_given_cookie',
34
+ body: {
35
+ remember: false,
36
+ scope: 'user',
37
+ },
38
+ });
39
+ expect({
40
+ response,
41
+ authCookiesParseCalls: authCookies.parse.mock.calls,
42
+ authCookiesBuildCalls: authCookies.build.mock.calls,
43
+ postOAuth2TokenCalls: postOAuth2Token.mock.calls,
44
+ }).toMatchInlineSnapshot(`
49
45
  Object {
50
46
  "authCookiesBuildCalls": Array [
51
47
  Array [
@@ -88,12 +84,14 @@ describe('postAuthRefresh', () => {
88
84
  "token_type": "bearer",
89
85
  },
90
86
  "headers": Object {
91
- "Set-Cookie": "the_build_cookies",
87
+ "Set-Cookie": Array [
88
+ "the_build_cookies",
89
+ ],
92
90
  },
93
91
  "status": 200,
94
92
  },
95
93
  }
96
94
  `);
97
- });
95
+ });
98
96
  });
99
97
  //# sourceMappingURL=postAuthRefresh.test.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postAuthRefresh.test.ts"],"names":["describe","test","authCookies","parse","jest","fn","build","postOAuth2Token","postAuthRefresh","ROOT_AUTHENTICATION_DATA","scope","applicationId","mockReturnValueOnce","access_token","refresh_token","mockResolvedValueOnce","status","body","expiration_date","expires_in","token_type","response","cookie","remember","expect","authCookiesParseCalls","mock","calls","authCookiesBuildCalls","postOAuth2TokenCalls","toMatchInlineSnapshot"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChCC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL,EADW;AAElBC,MAAAA,KAAK,EAAEF,IAAI,CAACC,EAAL;AAFW,KAApB;AAIA,UAAME,eAAe,GAAGH,IAAI,CAACC,EAAL,EAAxB;AACA,UAAMG,eAAe,GAAG,MAAM,8BAAoB;AAChDC,MAAAA,w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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KArDI;AAsDD,GA5FG,CAAJ;AA6FD,CA9FO,CAAR","sourcesContent":["import initPostAuthRefresh from './postAuthRefresh';\n\ndescribe('postAuthRefresh', () => {\n test('should work', async () => {\n const authCookies = {\n parse: jest.fn(),\n build: jest.fn(),\n };\n const postOAuth2Token = jest.fn();\n const postAuthRefresh = await initPostAuthRefresh({\n ROOT_AUTHENTICATION_DATA: {\n scope: 'user',\n applicationId: 'root_app_id',\n },\n authCookies,\n postOAuth2Token,\n });\n\n authCookies.parse.mockReturnValueOnce({\n access_token: 'an_access_token',\n refresh_token: 'a_refresh_token',\n });\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n postOAuth2Token.mockResolvedValueOnce({\n status: 200,\n body: {\n access_token: 'an_access_token',\n expiration_date: '2020-02-02T20:22:02Z',\n expires_in: 3600,\n token_type: 'bearer',\n },\n });\n\n const response = await postAuthRefresh({\n cookie: 'a_given_cookie',\n body: {\n remember: false,\n scope: 'user',\n },\n });\n\n expect({\n response,\n authCookiesParseCalls: authCookies.parse.mock.calls,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n postOAuth2TokenCalls: postOAuth2Token.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [\n Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n Object {\n \"session\": true,\n },\n ],\n ],\n \"authCookiesParseCalls\": Array [\n Array [\n \"a_given_cookie\",\n ],\n ],\n \"postOAuth2TokenCalls\": Array [\n Array [\n Object {\n \"authenticationData\": Object {\n \"applicationId\": \"root_app_id\",\n \"scope\": \"user\",\n },\n \"body\": Object {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": \"a_refresh_token\",\n \"scope\": \"user\",\n },\n },\n ],\n ],\n \"response\": Object {\n \"body\": Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 200,\n },\n }\n `);\n });\n});\n"],"file":"postAuthRefresh.test.js"}
1
+ {"version":3,"file":"postAuthRefresh.test.js","sourceRoot":"","sources":["../../src/handlers/postAuthRefresh.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,mBAAmB,MAAM,sBAAsB,CAAC;AAGvD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,WAAW,GAAG;YAClB,KAAK,EAAE,IAAI,CAAC,EAAE,EAA+B;YAC7C,KAAK,EAAE,IAAI,CAAC,EAAE,EAA+B;SAC9C,CAAC;QACF,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,EAAO,CAAC;QACvC,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC;YAChD,wBAAwB,EAAE;gBACxB,KAAK,EAAE,MAAM;gBACb,aAAa,EAAE,aAAa;aAC7B;YACD,WAAW;YACX,eAAe;SAChB,CAAC,CAAC;QAEH,WAAW,CAAC,KAAK,CAAC,mBAAmB,CAAC;YACpC,YAAY,EAAE,iBAAiB;YAC/B,aAAa,EAAE,iBAAiB;SACjC,CAAC,CAAC;QACH,WAAW,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7D,eAAe,CAAC,qBAAqB,CAAC;YACpC,MAAM,EAAE,GAAG;YACX,IAAI,EAAE;gBACJ,YAAY,EAAE,iBAAiB;gBAC/B,eAAe,EAAE,sBAAsB;gBACvC,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,QAAQ;aACrB;SACF,C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