@whook/oauth2 9.0.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 (131) hide show
  1. package/README.md +20 -15
  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 +15 -15
  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 +1 -0
  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 +46 -88
  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 +15 -15
  78. package/src/services/authCookies.test.ts +2 -2
  79. package/src/services/authCookies.ts +2 -1
  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,12 +1,12 @@
1
1
  import { autoService } from 'knifecycle';
2
2
  import { noop } from '@whook/whook';
3
- import YError from 'yerror';
3
+ import { YError } from 'yerror';
4
4
  import type { LogService } from 'common-services';
5
5
  import type {
6
6
  OAuth2GranterService,
7
7
  OAuth2PasswordService,
8
8
  CheckApplicationService,
9
- } from './oAuth2Granters';
9
+ } from './oAuth2Granters.js';
10
10
  import type { BaseAuthenticationData } from '@whook/authorization';
11
11
 
12
12
  export type OAuth2PasswordGranterDependencies = {
@@ -1,12 +1,12 @@
1
1
  import { autoService } from 'knifecycle';
2
2
  import { noop } from '@whook/whook';
3
- import YError from 'yerror';
3
+ import { YError } from 'yerror';
4
4
  import type { LogService } from 'common-services';
5
5
  import type {
6
6
  OAuth2GranterService,
7
7
  CheckApplicationService,
8
8
  OAuth2RefreshTokenService,
9
- } from './oAuth2Granters';
9
+ } from './oAuth2Granters.js';
10
10
  import type { BaseAuthenticationData } from '@whook/authorization';
11
11
 
12
12
  export type OAuth2RefreshTokenGranterDependencies = {
@@ -6,7 +6,7 @@ import type {
6
6
  OAuth2AccessTokenService,
7
7
  CheckApplicationService,
8
8
  OAuth2CodeService,
9
- } from './oAuth2Granters';
9
+ } from './oAuth2Granters.js';
10
10
  import type { BaseAuthenticationData } from '@whook/authorization';
11
11
 
12
12
  export const IMPLICIT_GRANTER_TYPE = 'token';
@@ -1,160 +0,0 @@
1
- import { handler as _handler } from 'knifecycle';
2
- import camelCase from 'camelcase';
3
- import YError from 'yerror';
4
- import { refersTo } from '@whook/whook';
5
-
6
- /* Architecture Note #1: OAuth2 authorize
7
- This endpoint simply redirect the user to the authentication
8
- server page by first checking the application details are
9
- fine.
10
- */
11
- export const responseTypeParameter = {
12
- name: 'responseType',
13
- parameter: {
14
- in: 'query',
15
- name: 'response_type',
16
- required: true,
17
- schema: {
18
- type: 'string',
19
- enum: ['code', 'token']
20
- }
21
- }
22
- };
23
- export const clientIdParameter = {
24
- name: 'clientId',
25
- parameter: {
26
- in: 'query',
27
- name: 'client_id',
28
- required: true,
29
- schema: {
30
- type: 'string'
31
- }
32
- }
33
- };
34
- export const redirectURIParameter = {
35
- name: 'redirectURI',
36
- parameter: {
37
- in: 'query',
38
- name: 'redirect_uri',
39
- required: false,
40
- schema: {
41
- type: 'string',
42
- pattern: '^https?://',
43
- format: 'uri'
44
- }
45
- }
46
- };
47
- export const scopeParameter = {
48
- name: 'scope',
49
- parameter: {
50
- in: 'query',
51
- name: 'scope',
52
- description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
53
- required: false,
54
- schema: {
55
- type: 'string'
56
- }
57
- }
58
- };
59
- export const stateParameter = {
60
- name: 'state',
61
- parameter: {
62
- in: 'query',
63
- name: 'state',
64
- required: true,
65
- schema: {
66
- type: 'string'
67
- }
68
- }
69
- };
70
- export const definition = {
71
- method: 'get',
72
- path: '/oauth2/authorize',
73
- operation: {
74
- operationId: 'getOAuth2Authorize',
75
- summary: `Implements the [Authorization Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1)
76
- as defined per the OAuth2 RFC.`,
77
- tags: ['oauth2'],
78
- parameters: [refersTo(responseTypeParameter), refersTo(clientIdParameter), refersTo(redirectURIParameter), refersTo(scopeParameter), refersTo(stateParameter)],
79
- responses: {
80
- '302': {
81
- description: 'Redirects the user to the authorization interface.'
82
- }
83
- }
84
- }
85
- };
86
- export default _handler(getOAuth2Authorize, "getOAuth2Authorize", ["OAUTH2", "ERRORS_DESCRIPTORS", "oAuth2Granters", "log"]);
87
-
88
- async function getOAuth2Authorize({
89
- OAUTH2,
90
- ERRORS_DESCRIPTORS,
91
- oAuth2Granters,
92
- log
93
- }, {
94
- response_type: responseType,
95
- client_id: clientId,
96
- redirect_uri: demandedRedirectURI = '',
97
- scope: demandedScope = '',
98
- state,
99
- ...authorizeParameters
100
- }) {
101
- const url = new URL(OAUTH2.authenticateURL);
102
-
103
- try {
104
- const granter = oAuth2Granters.find(granter => granter.authorizer && granter.authorizer.responseType === responseType);
105
-
106
- if (!granter) {
107
- throw new YError('E_UNKNOWN_AUTHORIZER_TYPE', responseType);
108
- }
109
-
110
- const {
111
- applicationId,
112
- redirectURI,
113
- scope
114
- } = await granter.authorizer.authorize({
115
- clientId,
116
- redirectURI: demandedRedirectURI,
117
- scope: demandedScope
118
- }, camelCaseObjectProperties(authorizeParameters));
119
- url.searchParams.set('type', responseType);
120
- url.searchParams.set('redirect_uri', redirectURI);
121
- url.searchParams.set('scope', scope);
122
- url.searchParams.set('client_id', applicationId);
123
- } catch (err) {
124
- log('debug', '👫 - OAuth2 initialization error', err.code);
125
- log('debug-stack', err.stack || 'no_stack_trace');
126
- url.searchParams.set('redirect_uri', demandedRedirectURI);
127
- setURLError(url, err, ERRORS_DESCRIPTORS[err.code] || ERRORS_DESCRIPTORS.E_OAUTH2);
128
- }
129
-
130
- if (state) {
131
- url.searchParams.set('state', state);
132
- }
133
-
134
- return {
135
- status: 302,
136
- headers: {
137
- location: url.href
138
- }
139
- };
140
- } // The OAuth2 standard uses snake case names so we are
141
- // converting them to the project standards asap
142
-
143
-
144
- export function camelCaseObjectProperties(object) {
145
- return Object.keys(object).reduce((camelCasedObject, key) => {
146
- const newKey = key === 'redirect_uri' ? 'redirectURI' : camelCase(key);
147
- camelCasedObject[newKey] = object[key];
148
- return camelCasedObject;
149
- }, {});
150
- }
151
- export function setURLError(url, err, oAuth2Error) {
152
- url.searchParams.set('error', oAuth2Error.code);
153
-
154
- if (oAuth2Error.description) {
155
- url.searchParams.set('error_decription', oAuth2Error.description.replace(/\$([0-9]+)/g, (_, paramIndex) => {
156
- return (err.params || [])[parseInt(paramIndex, 10)];
157
- }));
158
- }
159
- }
160
- //# sourceMappingURL=getOAuth2Authorize.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOAuth2Authorize.mjs","names":["autoHandler","camelCase","YError","refersTo","responseTypeParameter","name","parameter","in","required","schema","type","enum","clientIdParameter","redirectURIParameter","pattern","format","scopeParameter","description","stateParameter","definition","method","path","operation","operationId","summary","tags","parameters","responses","getOAuth2Authorize","OAUTH2","ERRORS_DESCRIPTORS","oAuth2Granters","log","response_type","responseType","client_id","clientId","redirect_uri","demandedRedirectURI","scope","demandedScope","state","authorizeParameters","url","URL","authenticateURL","granter","find","authorizer","applicationId","redirectURI","authorize","camelCaseObjectProperties","searchParams","set","err","code","stack","setURLError","E_OAUTH2","status","headers","location","href","object","Object","keys","reduce","camelCasedObject","key","newKey","oAuth2Error","replace","_","paramIndex","params","parseInt"],"sources":["../../src/handlers/getOAuth2Authorize.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport camelCase from 'camelcase';\nimport YError from 'yerror';\nimport { refersTo } from '@whook/whook';\nimport type {\n WhookAPIHandlerDefinition,\n WhookAPIParameterDefinition,\n WhookResponse,\n WhookErrorsDescriptors,\n WhookErrorDescriptor,\n} from '@whook/whook';\nimport type {\n OAuth2Options,\n OAuth2GranterService,\n} from '../services/oAuth2Granters';\nimport type { LogService } from 'common-services';\n\n/* Architecture Note #1: OAuth2 authorize\nThis endpoint simply redirect the user to the authentication\n server page by first checking the application details are\n fine.\n*/\n\nexport const responseTypeParameter: WhookAPIParameterDefinition = {\n name: 'responseType',\n parameter: {\n in: 'query',\n name: 'response_type',\n required: true,\n schema: {\n type: 'string',\n enum: ['code', 'token'],\n },\n },\n};\nexport const clientIdParameter: WhookAPIParameterDefinition = {\n name: 'clientId',\n parameter: {\n in: 'query',\n name: 'client_id',\n required: true,\n schema: {\n type: 'string',\n },\n },\n};\nexport const redirectURIParameter: WhookAPIParameterDefinition = {\n name: 'redirectURI',\n parameter: {\n in: 'query',\n name: 'redirect_uri',\n required: false,\n schema: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n};\nexport const scopeParameter: WhookAPIParameterDefinition = {\n name: 'scope',\n parameter: {\n in: 'query',\n name: 'scope',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n required: false,\n schema: {\n type: 'string',\n },\n },\n};\nexport const stateParameter: WhookAPIParameterDefinition = {\n name: 'state',\n parameter: {\n in: 'query',\n name: 'state',\n required: true,\n schema: {\n type: 'string',\n },\n },\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'get',\n path: '/oauth2/authorize',\n operation: {\n operationId: 'getOAuth2Authorize',\n summary: `Implements the [Authorization Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1)\n as defined per the OAuth2 RFC.`,\n tags: ['oauth2'],\n parameters: [\n refersTo(responseTypeParameter),\n refersTo(clientIdParameter),\n refersTo(redirectURIParameter),\n refersTo(scopeParameter),\n refersTo(stateParameter),\n ],\n responses: {\n '302': {\n description: 'Redirects the user to the authorization interface.',\n },\n },\n },\n};\n\nexport default autoHandler(getOAuth2Authorize);\n\nasync function getOAuth2Authorize(\n {\n OAUTH2,\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n log,\n }: {\n OAUTH2: OAuth2Options;\n ERRORS_DESCRIPTORS: WhookErrorsDescriptors;\n oAuth2Granters: OAuth2GranterService[];\n log: LogService;\n },\n {\n response_type: responseType,\n client_id: clientId,\n redirect_uri: demandedRedirectURI = '',\n scope: demandedScope = '',\n state,\n ...authorizeParameters\n }: {\n response_type: string;\n client_id: string;\n redirect_uri?: string;\n scope?: string;\n state: string;\n } & Record<string, unknown>,\n): Promise<WhookResponse<302, { location: string }>> {\n const url = new URL(OAUTH2.authenticateURL);\n\n try {\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.authorizer && granter.authorizer.responseType === responseType,\n );\n\n if (!granter) {\n throw new YError('E_UNKNOWN_AUTHORIZER_TYPE', responseType);\n }\n\n const { applicationId, redirectURI, scope } = await (\n granter.authorizer as NonNullable<OAuth2GranterService['authorizer']>\n ).authorize(\n {\n clientId,\n redirectURI: demandedRedirectURI,\n scope: demandedScope,\n },\n camelCaseObjectProperties(authorizeParameters),\n );\n\n url.searchParams.set('type', responseType);\n url.searchParams.set('redirect_uri', redirectURI);\n url.searchParams.set('scope', scope);\n url.searchParams.set('client_id', applicationId);\n } catch (err) {\n log('debug', '👫 - OAuth2 initialization error', (err as YError).code);\n log('debug-stack', (err as Error).stack || 'no_stack_trace');\n\n url.searchParams.set('redirect_uri', demandedRedirectURI);\n setURLError(\n url,\n err as YError,\n ERRORS_DESCRIPTORS[(err as YError).code] || ERRORS_DESCRIPTORS.E_OAUTH2,\n );\n }\n\n if (state) {\n url.searchParams.set('state', state);\n }\n\n return {\n status: 302,\n headers: {\n location: url.href,\n },\n };\n}\n\n// The OAuth2 standard uses snake case names so we are\n// converting them to the project standards asap\nexport function camelCaseObjectProperties<T>(\n object: Record<string, T>,\n): Record<string, T> {\n return Object.keys(object).reduce((camelCasedObject, key) => {\n const newKey = key === 'redirect_uri' ? 'redirectURI' : camelCase(key);\n\n camelCasedObject[newKey] = object[key];\n return camelCasedObject;\n }, {});\n}\n\nexport function setURLError(\n url: URL,\n err: YError | Error,\n oAuth2Error: WhookErrorDescriptor,\n): void {\n url.searchParams.set('error', oAuth2Error.code);\n if (oAuth2Error.description) {\n url.searchParams.set(\n 'error_decription',\n oAuth2Error.description.replace(/\\$([0-9]+)/g, (_, paramIndex) => {\n return ((err as YError).params || [])[parseInt(paramIndex, 10)];\n }),\n );\n }\n}\n"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,OAAOC,SAAP,MAAsB,WAAtB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,QAAT,QAAyB,cAAzB;;AAcA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAMC,qBAAkD,GAAG;EAChEC,IAAI,EAAE,cAD0D;EAEhEC,SAAS,EAAE;IACTC,EAAE,EAAE,OADK;IAETF,IAAI,EAAE,eAFG;IAGTG,QAAQ,EAAE,IAHD;IAITC,MAAM,EAAE;MACNC,IAAI,EAAE,QADA;MAENC,IAAI,EAAE,CAAC,MAAD,EAAS,OAAT;IAFA;EAJC;AAFqD,CAA3D;AAYP,OAAO,MAAMC,iBAA8C,GAAG;EAC5DP,IAAI,EAAE,UADsD;EAE5DC,SAAS,EAAE;IACTC,EAAE,EAAE,OADK;IAETF,IAAI,EAAE,WAFG;IAGTG,QAAQ,EAA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AAhC,EAA+C,CAACC,CAAD,EAAIC,UAAJ,KAAmB;MAChE,OAAO,CAAEnB,GAAD,CAAgBoB,MAAhB,IAA0B,EAA3B,EAA+BC,QAAQ,CAACF,UAAD,EAAa,EAAb,CAAvC,CAAP;IACD,CAFD,CAFF;EAMD;AACF"}
@@ -1,114 +0,0 @@
1
- import initGetOAuth2Authorize from './getOAuth2Authorize';
2
- import { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';
3
- import { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';
4
- import YError from 'yerror';
5
- describe('getOAuth2Authorize', () => {
6
- const OAUTH2 = {
7
- authenticateURL: 'https://auth.example.com/sign_in'
8
- };
9
- const ERRORS_DESCRIPTORS = { ...DEFAULT_ERRORS_DESCRIPTORS,
10
- ...OAUTH2_ERRORS_DESCRIPTORS
11
- };
12
- const log = jest.fn();
13
- const codeGranter = {
14
- type: 'code',
15
- authorizer: {
16
- responseType: 'code',
17
- authorize: jest.fn()
18
- },
19
- acknowledger: {
20
- acknowledgmentType: 'code',
21
- acknowledge: jest.fn()
22
- },
23
- authenticator: {
24
- grantType: 'authorization_code',
25
- authenticate: jest.fn()
26
- }
27
- };
28
- const tokenGranter = {
29
- type: 'token',
30
- authorizer: {
31
- responseType: 'token',
32
- authorize: jest.fn()
33
- },
34
- acknowledger: {
35
- acknowledgmentType: 'token',
36
- acknowledge: jest.fn()
37
- }
38
- };
39
- const oAuth2Granters = [codeGranter, tokenGranter];
40
- beforeEach(() => {
41
- log.mockReset();
42
- [codeGranter.authorizer.authorize, codeGranter.acknowledger.acknowledge, codeGranter.authenticator.authenticate, tokenGranter.authorizer.authorize, tokenGranter.acknowledger.acknowledge].forEach(mock => mock.mockReset());
43
- });
44
- test('should redirect', async () => {
45
- [codeGranter.acknowledger.acknowledge, codeGranter.authenticator.authenticate, tokenGranter.authorizer.authorize, tokenGranter.acknowledger.acknowledge].forEach(mock => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
46
- codeGranter.authorizer.authorize.mockResolvedValueOnce({
47
- applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
48
- redirectURI: 'http://lol',
49
- scope: 'user'
50
- });
51
- const getOAuth2Authorize = await initGetOAuth2Authorize({
52
- OAUTH2,
53
- ERRORS_DESCRIPTORS,
54
- oAuth2Granters,
55
- log
56
- });
57
- const response = await getOAuth2Authorize({
58
- response_type: 'code',
59
- client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
60
- redirect_uri: 'https://www.example.com',
61
- scope: 'user',
62
- state: 'bancal'
63
- });
64
- expect(response).toMatchInlineSnapshot(`
65
- Object {
66
- "headers": Object {
67
- "location": "https://auth.example.com/sign_in?type=code&redirect_uri=http%3A%2F%2Flol&scope=user&client_id=abbacaca-abba-caca-abba-cacaabbacaca&state=bancal",
68
- },
69
- "status": 302,
70
- }
71
- `);
72
- expect({
73
- logCalls: log.mock.calls.filter(args => args[0].endsWith('stack')),
74
- codeGranterAuthorizerAuthorizeCalls: codeGranter.authorizer.authorize.mock.calls,
75
- codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledger.acknowledge.mock.calls,
76
- codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticator.authenticate.mock.calls,
77
- tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorizer.authorize.mock.calls,
78
- tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledger.acknowledge.mock.calls
79
- }).toMatchSnapshot();
80
- });
81
- test('should redirect with an error when some', async () => {
82
- [codeGranter.authorizer.authorize, codeGranter.acknowledger.acknowledge, codeGranter.authenticator.authenticate, tokenGranter.authorizer.authorize, tokenGranter.acknowledger.acknowledge].forEach(mock => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
83
- const getOAuth2Authorize = await initGetOAuth2Authorize({
84
- OAUTH2,
85
- ERRORS_DESCRIPTORS,
86
- oAuth2Granters,
87
- log
88
- });
89
- const response = await getOAuth2Authorize({
90
- response_type: 'yolo',
91
- client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
92
- redirect_uri: 'https://www.example.com',
93
- scope: 'user',
94
- state: 'bancal'
95
- });
96
- expect(response).toMatchInlineSnapshot(`
97
- Object {
98
- "headers": Object {
99
- "location": "https://auth.example.com/sign_in?redirect_uri=https%3A%2F%2Fwww.example.com&error=unsupported_response_type&error_decription=The+type+%22yolo%22+is+not+supported.&state=bancal",
100
- },
101
- "status": 302,
102
- }
103
- `);
104
- expect({
105
- logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
106
- codeGranterAuthorizerAuthorizeCalls: codeGranter.authorizer.authorize.mock.calls,
107
- codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledger.acknowledge.mock.calls,
108
- codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticator.authenticate.mock.calls,
109
- tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorizer.authorize.mock.calls,
110
- tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledger.acknowledge.mock.calls
111
- }).toMatchSnapshot();
112
- });
113
- });
114
- //# sourceMappingURL=getOAuth2Authorize.test.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOAuth2Authorize.test.mjs","names":["initGetOAuth2Authorize","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","YError","describe","OAUTH2","authenticateURL","ERRORS_DESCRIPTORS","log","jest","fn","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","mockResolvedValueOnce","applicationId","redirectURI","scope","getOAuth2Authorize","response","response_type","client_id","redirect_uri","state","expect","toMatchInlineSnapshot","logCalls","calls","filter","args","endsWith","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"sources":["../../src/handlers/getOAuth2Authorize.test.ts"],"sourcesContent":["import initGetOAuth2Authorize from './getOAuth2Authorize';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport YError from 'yerror';\nimport type { OAuth2Options, OAuth2GranterService } from '..';\n\ndescribe('getOAuth2Authorize', () => {\n const OAUTH2: OAuth2Options = {\n authenticateURL: 'https://auth.example.com/sign_in',\n };\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const log = jest.fn();\n const codeGranter = {\n type: 'code',\n authorizer: { responseType: 'code', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'code', acknowledge: jest.fn() },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: jest.fn(),\n },\n };\n const tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const oAuth2Granters: OAuth2GranterService[] = [codeGranter, tokenGranter];\n\n beforeEach(() => {\n log.mockReset();\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) => mock.mockReset());\n });\n\n test('should redirect', async () => {\n [\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n });\n\n const getOAuth2Authorize = await initGetOAuth2Authorize({\n OAUTH2,\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n log,\n });\n const response = await getOAuth2Authorize({\n response_type: 'code',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n });\n\n expect(response).toMatchInlineSnapshot(`\n Object {\n \"headers\": Object {\n \"location\": \"https://auth.example.com/sign_in?type=code&redirect_uri=http%3A%2F%2Flol&scope=user&client_id=abbacaca-abba-caca-abba-cacaabbacaca&state=bancal\",\n },\n \"status\": 302,\n }\n `);\n expect({\n logCalls: log.mock.calls.filter((args) => args[0].endsWith('stack')),\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n\n test('should redirect with an error when some', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const getOAuth2Authorize = await initGetOAuth2Authorize({\n OAUTH2,\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n log,\n });\n const response = await getOAuth2Authorize({\n response_type: 'yolo',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n });\n\n expect(response).toMatchInlineSnapshot(`\n Object {\n \"headers\": Object {\n \"location\": \"https://auth.example.com/sign_in?redirect_uri=https%3A%2F%2Fwww.example.com&error=unsupported_response_type&error_decription=The+type+%22yolo%22+is+not+supported.&state=bancal\",\n },\n \"status\": 302,\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,sBAAnC;AACA,SAASC,0BAAT,QAA2C,cAA3C;AACA,SAASC,yBAAT,QAA0C,4BAA1C;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAGAC,QAAQ,CAAC,oBAAD,EAAuB,MAAM;EACnC,MAAMC,MAAqB,GAAG;IAC5BC,eAAe,EAAE;EADW,CAA9B;EAGA,MAAMC,kBAAkB,GAAG,EACzB,GAAGN,0BADsB;IAEzB,GAAGC;EAFsB,CAA3B;EAIA,MAAMM,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;EACA,MAAMC,WAAW,GAAG;IAClBC,IAAI,EAAE,MADY;IAElBC,UAAU,EAAE;MAAEC,YAAY,EAAE,MAAhB;MAAwBC,SAAS,EAAEN,IAAI,CAACC,EAAL;IAAnC,CAFM;IAGlBM,YAAY,EAAE;MAAEC,kBAAkB,EAAE,MAAtB;MAA8BC,WAAW,EAAET,IAAI,CAACC,EAAL;IAA3C,CAHI;IAIlBS,aAAa,EAAE;MACbC,SAAS,EAAE,oBADE;MAEbC,YAAY,EAAEZ,IAAI,CAACC,EAAL;IAFD;EAJG,CAApB;EASA,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+0,0 @@
1
- import { handler as _handler } from 'knifecycle';
2
- import YHTTPError from 'yhttperror';
3
- import { AUTH_API_PREFIX } from '../services/authCookies';
4
- export const definition = {
5
- method: 'post',
6
- path: `${AUTH_API_PREFIX}/login`,
7
- operation: {
8
- operationId: 'postAuthLogin',
9
- summary: 'Logs a user in',
10
- tags: ['auth'],
11
- 'x-whook': {
12
- disabled: true
13
- },
14
- parameters: [],
15
- requestBody: {
16
- required: true,
17
- content: {
18
- 'application/json': {
19
- schema: {
20
- type: 'object',
21
- required: ['username', 'password'],
22
- properties: {
23
- username: {
24
- type: 'string'
25
- },
26
- password: {
27
- type: 'string'
28
- },
29
- scope: {
30
- type: 'string'
31
- },
32
- remember: {
33
- type: 'boolean'
34
- }
35
- }
36
- }
37
- }
38
- }
39
- },
40
- responses: {
41
- 200: {
42
- description: 'Successfuly logged in.',
43
- content: {
44
- 'application/json': {
45
- schema: {
46
- type: 'object',
47
- properties: {
48
- access_token: {
49
- type: 'string'
50
- },
51
- expiration_date: {
52
- type: 'string'
53
- },
54
- expires_in: {
55
- type: 'string'
56
- },
57
- token_type: {
58
- type: 'string'
59
- }
60
- }
61
- }
62
- }
63
- }
64
- }
65
- }
66
- }
67
- };
68
- export default _handler(postAuthLogin, "postAuthLogin", ["ROOT_AUTHENTICATION_DATA", "authCookies", "postOAuth2Token"]);
69
-
70
- async function postAuthLogin({
71
- ROOT_AUTHENTICATION_DATA,
72
- authCookies,
73
- postOAuth2Token
74
- }, {
75
- body
76
- }) {
77
- try {
78
- const response = await postOAuth2Token({
79
- body: {
80
- grant_type: 'password',
81
- scope: body.scope,
82
- username: body.username,
83
- password: body.password
84
- },
85
- authenticationData: ROOT_AUTHENTICATION_DATA
86
- });
87
- return { ...response,
88
- headers: { ...(response.headers || {}),
89
- 'Set-Cookie': authCookies.build(response.status === 200 ? response.body : undefined, {
90
- session: !body.remember
91
- })
92
- },
93
- body: {
94
- access_token: response.body.access_token,
95
- expiration_date: response.body.expiration_date,
96
- expires_in: response.body.expires_in,
97
- token_type: response.body.token_type
98
- }
99
- };
100
- } catch (err) {
101
- const newErr = YHTTPError.wrap(err);
102
- newErr.headers = { ...(err.headers || {}),
103
- // TODO: Allow string[] in YHTTPError
104
- 'Set-Cookie': authCookies.build()
105
- };
106
- throw newErr;
107
- }
108
- }
109
- //# sourceMappingURL=postAuthLogin.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postAuthLogin.mjs","names":["autoHandler","YHTTPError","AUTH_API_PREFIX","definition","method","path","operation","operationId","summary","tags","disabled","parameters","requestBody","required","content","schema","type","properties","username","password","scope","remember","responses","description","access_token","expiration_date","expires_in","token_type","postAuthLogin","ROOT_AUTHENTICATION_DATA","authCookies","postOAuth2Token","body","response","grant_type","authenticationData","headers","build","status","undefined","session","err","newErr","wrap"],"sources":["../../src/handlers/postAuthLogin.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YHTTPError from 'yhttperror';\nimport initPostOauth2Token from './postOAuth2Token';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type { WhookAPIHandlerDefinition } 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 definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/login`,\n operation: {\n operationId: 'postAuthLogin',\n summary: 'Logs a user in',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['username', 'password'],\n properties: {\n username: { type: 'string' },\n password: { type: 'string' },\n scope: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successfuly logged in.',\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(postAuthLogin);\n\nasync function postAuthLogin<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ROOT_AUTHENTICATION_DATA,\n authCookies,\n postOAuth2Token,\n }: AuthHandlersConfig<AUTHENTICATION_DATA> & {\n authCookies: Pick<AuthCookiesService, 'build'>;\n postOAuth2Token: AsyncReturnType<typeof initPostOauth2Token>;\n },\n {\n body,\n }: {\n body: {\n username: string;\n password: string;\n scope: string;\n remember: boolean;\n };\n },\n) {\n try {\n const response = await postOAuth2Token({\n body: {\n grant_type: 'password',\n scope: body.scope,\n username: body.username,\n password: body.password,\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 as Error);\n\n newErr.headers = {\n ...((err as YHTTPError).headers || {}),\n // TODO: Allow string[] in YHTTPError\n 'Set-Cookie': authCookies.build() as unknown as string,\n };\n\n throw newErr;\n }\n}\n"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA,SAASC,eAAT,QAAgC,yBAAhC;AASA,OAAO,MAAMC,UAAqC,GAAG;EACnDC,MAAM,EAAE,MAD2C;EAEnDC,IAAI,EAAG,GAAEH,eAAgB,QAF0B;EAGnDI,SAAS,EAAE;IACTC,WAAW,EAAE,eADJ;IAETC,OAAO,EAAE,gBAFA;IAGTC,IAAI,EAAE,CAAC,MAAD,CAHG;IAIT,WAAW;MACTC,QAAQ,EAAE;IADD,CAJF;IAOTC,UAAU,EAAE,EAP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PiB,CAAD,CAAtC;IAUA,OAAO,EACL,GAAGI,QADE;MAELG,OAAO,EAAE,EACP,IAAIH,QAAQ,CAACG,OAAT,IAAoB,EAAxB,CADO;QAEP,cAAcN,WAAW,CAACO,KAAZ,CACZJ,QAAQ,CAACK,MAAT,KAAoB,GAApB,GAA0BL,QAAQ,CAACD,IAAnC,GAA0CO,SAD9B,EAEZ;UAAEC,OAAO,EAAE,CAACR,IAAI,CAACX;QAAjB,CAFY;MAFP,CAFJ;MASLW,IAAI,EAAE;QACJR,YAAY,EAAES,QAAQ,CAACD,IAAT,CAAcR,YADxB;QAEJC,eAAe,EAAEQ,QAAQ,CAACD,IAAT,CAAcP,eAF3B;QAGJC,UAAU,EAAEO,QAAQ,CAACD,IAAT,CAAcN,UAHtB;QAIJC,UAAU,EAAEM,QAAQ,CAACD,IAAT,CAAcL;MAJtB;IATD,CAAP;EAgBD,CA3BD,CA2BE,OAAOc,GAAP,EAAY;IACZ,MAAMC,MAAM,GAAGzC,UAAU,CAAC0C,IAAX,CAAgBF,GAAhB,CAAf;IAEAC,MAAM,CAACN,OAAP,GAAiB,EACf,IAAKK,GAAD,CAAoBL,OAApB,IAA+B,EAAnC,CADe;MAEf;MACA,cAAcN,WAAW,CAACO,KAAZ;IAHC,CAAjB;IAMA,MAAMK,MAAN;EACD;AACF"}
@@ -1,85 +0,0 @@
1
- import initPostAuthLogin from './postAuthLogin';
2
- describe('postAuthLogin', () => {
3
- test('should work', async () => {
4
- const authCookies = {
5
- build: jest.fn()
6
- };
7
- const postOAuth2Token = jest.fn();
8
- const postAuthLogin = await initPostAuthLogin({
9
- ROOT_AUTHENTICATION_DATA: {
10
- scope: 'user',
11
- applicationId: 'root_app_id'
12
- },
13
- authCookies,
14
- postOAuth2Token
15
- });
16
- authCookies.build.mockReturnValueOnce('the_build_cookies');
17
- postOAuth2Token.mockResolvedValueOnce({
18
- status: 200,
19
- body: {
20
- access_token: 'an_access_token',
21
- expiration_date: '2020-02-02T20:22:02Z',
22
- expires_in: 3600,
23
- token_type: 'bearer'
24
- }
25
- });
26
- const response = await postAuthLogin({
27
- body: {
28
- username: 'a_username',
29
- password: 'a_password',
30
- remember: false,
31
- scope: 'user'
32
- }
33
- });
34
- expect({
35
- response,
36
- authCookiesBuildCalls: authCookies.build.mock.calls,
37
- postOAuth2TokenCalls: postOAuth2Token.mock.calls
38
- }).toMatchInlineSnapshot(`
39
- Object {
40
- "authCookiesBuildCalls": Array [
41
- Array [
42
- Object {
43
- "access_token": "an_access_token",
44
- "expiration_date": "2020-02-02T20:22:02Z",
45
- "expires_in": 3600,
46
- "token_type": "bearer",
47
- },
48
- Object {
49
- "session": true,
50
- },
51
- ],
52
- ],
53
- "postOAuth2TokenCalls": Array [
54
- Array [
55
- Object {
56
- "authenticationData": Object {
57
- "applicationId": "root_app_id",
58
- "scope": "user",
59
- },
60
- "body": Object {
61
- "grant_type": "password",
62
- "password": "a_password",
63
- "scope": "user",
64
- "username": "a_username",
65
- },
66
- },
67
- ],
68
- ],
69
- "response": Object {
70
- "body": Object {
71
- "access_token": "an_access_token",
72
- "expiration_date": "2020-02-02T20:22:02Z",
73
- "expires_in": 3600,
74
- "token_type": "bearer",
75
- },
76
- "headers": Object {
77
- "Set-Cookie": "the_build_cookies",
78
- },
79
- "status": 200,
80
- },
81
- }
82
- `);
83
- });
84
- });
85
- //# sourceMappingURL=postAuthLogin.test.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postAuthLogin.test.mjs","names":["initPostAuthLogin","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"],"sources":["../../src/handlers/postAuthLogin.test.ts"],"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"],"mappings":"AAAA,OAAOA,iBAAP,MAA8B,iBAA9B;AAEAC,QAAQ,CAAC,eAAD,EAAkB,MAAM;EAC9BC,IAAI,CAAC,aAAD,EAAgB,YAAY;IAC9B,MAAMC,WAAW,GAAG;MAClBC,KAAK,EAAEC,IAAI,CAACC,EAAL;IADW,CAApB;IAGA,MAAMC,eAAe,GAAGF,IAAI,CAACC,EAAL,EAAxB;IACA,MAAME,aAAa,GAAG,MAAMR,iBAAiB,CAAC;MAC5CS,wBAAwB,EAAE;QACxBC,KAAK,EAAE,MADiB;QAExBC,aAAa,EAAE;MAFS,CADkB;MAK5CR,WAL4C;MAM5CI;IAN4C,CAAD,CAA7C;IASAJ,WAAW,CAACC,KAAZ,CAAkBQ,mBAAlB,CAAsC,mBAAtC;IACAL,eAAe,CAACM,qBAAhB,CAAsC;MACpCC,MAAM,EAAE,GAD4B;MAEpCC,IAAI,EAAE;QACJC,YAAY,EAAE,iBADV;QAEJC,eAAe,EAAE,sBAFb;QAGJC,UAAU,EAAE,IAHR;QAIJC,UAAU,EAAE;MAJR;IAF8B,CAAtC;IAUA,MAAMC,QAAQ,GAAG,MAAMZ,aAAa,CAAC;MACnCO,IAAI,EAAE;QACJM,QAAQ,EAAE,YADN;QAEJC,QAAQ,EAAE,YAFN;QAGJC,QAAQ,EAAE,KAHN;QAIJb,KAAK,EAAE;MAJH;IAD6B,CAAD,CAApC;IASAc,MAAM,CAAC;MACLJ,QADK;MAELK,qBAAqB,EAAEtB,WAAW,CAACC,KAAZ,CAAkBsB,IAAlB,CAAuBC,KAFzC;MAGLC,oBAAoB,EAAErB,eAAe,CAACmB,IAAhB,CAAqBC;IAHtC,CAAD,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;EAiDD,CAnFG,CAAJ;AAoFD,CArFO,CAAR"}
@@ -1,33 +0,0 @@
1
- import { handler as _handler } from 'knifecycle';
2
- import { AUTH_API_PREFIX } from '../services/authCookies';
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
- }
19
- }
20
- };
21
- export default _handler(postAuthLogout, "postAuthLogout", ["authCookies"]);
22
-
23
- async function postAuthLogout({
24
- authCookies
25
- }) {
26
- return {
27
- status: 204,
28
- headers: {
29
- 'Set-Cookie': authCookies.build()
30
- }
31
- };
32
- }
33
- //# sourceMappingURL=postAuthLogout.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postAuthLogout.mjs","names":["autoHandler","AUTH_API_PREFIX","definition","method","path","operation","operationId","summary","tags","disabled","parameters","responses","description","postAuthLogout","authCookies","status","headers","build"],"sources":["../../src/handlers/postAuthLogout.ts"],"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"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,eAAT,QAAgC,yBAAhC;AAIA,OAAO,MAAMC,UAAqC,GAAG;EACnDC,MAAM,EAAE,MAD2C;EAEnDC,IAAI,EAAG,GAAEH,eAAgB,SAF0B;EAGnDI,SAAS,EAAE;IACTC,WAAW,EAAE,gBADJ;IAETC,OAAO,EAAE,iBAFA;IAGTC,IAAI,EAAE,CAAC,MAAD,CAHG;IAIT,WAAW;MACTC,QAAQ,EAAE;IADD,CAJF;IAOTC,UAAU,EAAE,EAPH;IAQTC,SAAS,EAAE;MACT,KAAK;QACHC,WAAW,EAAE;MADV;IADI;EARF;AAHwC,CAA9C;AAmBP,eAAeZ,QAAW,CAACa,cAAD,oCAA1B;;AAEA,eAAeA,cAAf,CAA8B;EAC5BC;AAD4B,CAA9B,EAIG;EACD,OAAO;IACLC,MAAM,EAAE,GADH;IAELC,OAAO,EAAE;MACP,cAAcF,WAAW,CAACG,KAAZ;IADP;EAFJ,CAAP;AAMD"}
@@ -1,30 +0,0 @@
1
- import initPostAuthLogout from './postAuthLogout';
2
- describe('postAuthLogout', () => {
3
- test('should work', async () => {
4
- const authCookies = {
5
- build: jest.fn()
6
- };
7
- const postAuthLogout = await initPostAuthLogout({
8
- authCookies
9
- });
10
- authCookies.build.mockReturnValueOnce('the_build_cookies');
11
- const response = await postAuthLogout({});
12
- expect({
13
- response,
14
- authCookiesBuildCalls: authCookies.build.mock.calls
15
- }).toMatchInlineSnapshot(`
16
- Object {
17
- "authCookiesBuildCalls": Array [
18
- Array [],
19
- ],
20
- "response": Object {
21
- "headers": Object {
22
- "Set-Cookie": "the_build_cookies",
23
- },
24
- "status": 204,
25
- },
26
- }
27
- `);
28
- });
29
- });
30
- //# sourceMappingURL=postAuthLogout.test.mjs.map