@whook/oauth2 18.0.3 → 19.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 (112) hide show
  1. package/README.md +36 -46
  2. package/dist/index.d.ts +8 -8
  3. package/dist/index.js +6 -6
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.test.js +19 -18
  6. package/dist/index.test.js.map +1 -1
  7. package/dist/routes/getOAuth2Authorize.d.ts +100 -0
  8. package/dist/{handlers → routes}/getOAuth2Authorize.js +39 -36
  9. package/dist/routes/getOAuth2Authorize.js.map +1 -0
  10. package/dist/{handlers → routes}/getOAuth2Authorize.test.js +14 -10
  11. package/dist/routes/getOAuth2Authorize.test.js.map +1 -0
  12. package/dist/routes/postAuthLogin.d.ts +89 -0
  13. package/dist/{handlers → routes}/postAuthLogin.js +40 -39
  14. package/dist/routes/postAuthLogin.js.map +1 -0
  15. package/dist/routes/postAuthLogin.test.js.map +1 -0
  16. package/dist/routes/postAuthLogout.d.ts +28 -0
  17. package/dist/{handlers → routes}/postAuthLogout.js +9 -9
  18. package/dist/routes/postAuthLogout.js.map +1 -0
  19. package/dist/{handlers → routes}/postAuthLogout.test.js +1 -1
  20. package/dist/routes/postAuthLogout.test.js.map +1 -0
  21. package/dist/routes/postAuthRefresh.d.ts +94 -0
  22. package/dist/{handlers → routes}/postAuthRefresh.js +43 -42
  23. package/dist/routes/postAuthRefresh.js.map +1 -0
  24. package/dist/routes/postAuthRefresh.test.js.map +1 -0
  25. package/dist/routes/postOAuth2Acknowledge.d.ts +97 -0
  26. package/dist/{handlers → routes}/postOAuth2Acknowledge.js +46 -44
  27. package/dist/routes/postOAuth2Acknowledge.js.map +1 -0
  28. package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -0
  29. package/dist/routes/postOAuth2Token.d.ts +198 -0
  30. package/dist/{handlers → routes}/postOAuth2Token.js +36 -34
  31. package/dist/routes/postOAuth2Token.js.map +1 -0
  32. package/dist/routes/postOAuth2Token.test.js.map +1 -0
  33. package/dist/services/authCookies.d.ts +3 -3
  34. package/dist/services/authCookies.js.map +1 -1
  35. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +8 -8
  36. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  37. package/dist/services/oAuth2CodeGranter.d.ts +4 -5
  38. package/dist/services/oAuth2CodeGranter.js +2 -0
  39. package/dist/services/oAuth2CodeGranter.js.map +1 -1
  40. package/dist/services/oAuth2CodeGranter.test.js +2 -2
  41. package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
  42. package/dist/services/oAuth2Granters.d.ts +25 -25
  43. package/dist/services/oAuth2Granters.js +1 -1
  44. package/dist/services/oAuth2Granters.js.map +1 -1
  45. package/dist/services/oAuth2PasswordGranter.d.ts +4 -5
  46. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  47. package/dist/services/oAuth2RefreshTokenGranter.d.ts +4 -5
  48. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  49. package/dist/services/oAuth2TokenGranter.d.ts +4 -5
  50. package/dist/services/oAuth2TokenGranter.js +4 -0
  51. package/dist/services/oAuth2TokenGranter.js.map +1 -1
  52. package/package.json +10 -9
  53. package/src/__snapshots__/index.test.ts.snap +1 -0
  54. package/src/index.test.ts +39 -52
  55. package/src/index.ts +20 -20
  56. package/src/{handlers → routes}/getOAuth2Authorize.test.ts +18 -14
  57. package/src/routes/getOAuth2Authorize.ts +217 -0
  58. package/src/{handlers → routes}/postAuthLogin.test.ts +3 -2
  59. package/src/routes/postAuthLogin.ts +118 -0
  60. package/src/{handlers → routes}/postAuthLogout.test.ts +2 -2
  61. package/src/routes/postAuthLogout.ts +38 -0
  62. package/src/{handlers → routes}/postAuthRefresh.test.ts +3 -2
  63. package/src/routes/postAuthRefresh.ts +138 -0
  64. package/src/{handlers → routes}/postOAuth2Acknowledge.test.ts +23 -39
  65. package/src/{handlers → routes}/postOAuth2Acknowledge.ts +88 -96
  66. package/src/{handlers → routes}/postOAuth2Token.test.ts +12 -11
  67. package/src/{handlers → routes}/postOAuth2Token.ts +124 -129
  68. package/src/services/authCookies.test.ts +1 -1
  69. package/src/services/authCookies.ts +3 -5
  70. package/src/services/oAuth2ClientCredentialsGranter.ts +10 -15
  71. package/src/services/oAuth2CodeGranter.test.ts +12 -21
  72. package/src/services/oAuth2CodeGranter.ts +9 -11
  73. package/src/services/oAuth2Granters.ts +35 -57
  74. package/src/services/oAuth2PasswordGranter.ts +7 -11
  75. package/src/services/oAuth2RefreshTokenGranter.ts +7 -11
  76. package/src/services/oAuth2TokenGranter.ts +12 -12
  77. package/src/types.d.ts +7 -0
  78. package/dist/handlers/getOAuth2Authorize.d.ts +0 -27
  79. package/dist/handlers/getOAuth2Authorize.js.map +0 -1
  80. package/dist/handlers/getOAuth2Authorize.test.js.map +0 -1
  81. package/dist/handlers/postAuthLogin.d.ts +0 -28
  82. package/dist/handlers/postAuthLogin.js.map +0 -1
  83. package/dist/handlers/postAuthLogin.test.js.map +0 -1
  84. package/dist/handlers/postAuthLogout.d.ts +0 -12
  85. package/dist/handlers/postAuthLogout.js.map +0 -1
  86. package/dist/handlers/postAuthLogout.test.js.map +0 -1
  87. package/dist/handlers/postAuthRefresh.d.ts +0 -28
  88. package/dist/handlers/postAuthRefresh.js.map +0 -1
  89. package/dist/handlers/postAuthRefresh.test.js.map +0 -1
  90. package/dist/handlers/postOAuth2Acknowledge.d.ts +0 -31
  91. package/dist/handlers/postOAuth2Acknowledge.js.map +0 -1
  92. package/dist/handlers/postOAuth2Acknowledge.test.js.map +0 -1
  93. package/dist/handlers/postOAuth2Token.d.ts +0 -36
  94. package/dist/handlers/postOAuth2Token.js.map +0 -1
  95. package/dist/handlers/postOAuth2Token.test.js.map +0 -1
  96. package/src/handlers/getOAuth2Authorize.ts +0 -214
  97. package/src/handlers/postAuthLogin.ts +0 -123
  98. package/src/handlers/postAuthLogout.ts +0 -38
  99. package/src/handlers/postAuthRefresh.ts +0 -143
  100. /package/dist/{handlers → routes}/getOAuth2Authorize.test.d.ts +0 -0
  101. /package/dist/{handlers → routes}/postAuthLogin.test.d.ts +0 -0
  102. /package/dist/{handlers → routes}/postAuthLogin.test.js +0 -0
  103. /package/dist/{handlers → routes}/postAuthLogout.test.d.ts +0 -0
  104. /package/dist/{handlers → routes}/postAuthRefresh.test.d.ts +0 -0
  105. /package/dist/{handlers → routes}/postAuthRefresh.test.js +0 -0
  106. /package/dist/{handlers → routes}/postOAuth2Acknowledge.test.d.ts +0 -0
  107. /package/dist/{handlers → routes}/postOAuth2Acknowledge.test.js +0 -0
  108. /package/dist/{handlers → routes}/postOAuth2Token.test.d.ts +0 -0
  109. /package/dist/{handlers → routes}/postOAuth2Token.test.js +0 -0
  110. /package/src/{handlers → routes}/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -0
  111. /package/src/{handlers → routes}/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -0
  112. /package/src/{handlers → routes}/__snapshots__/postOAuth2Token.test.ts.snap +0 -0
@@ -1,54 +1,52 @@
1
- import { autoHandler, location } from 'knifecycle';
1
+ import { autoService, location } from 'knifecycle';
2
2
  import { camelCaseObjectProperties } from './getOAuth2Authorize.js';
3
- import { noop } from '@whook/whook';
4
3
  import { YError, printStackTrace } from 'yerror';
5
- import { refersTo } from '@whook/whook';
6
- import type { OpenAPIV3_1 } from 'openapi-types';
7
- import type { LogService, TimeService } from 'common-services';
8
- import type {
9
- WhookAPISchemaDefinition,
10
- WhookAPIHandlerDefinition,
4
+ import { type LogService, type TimeService } from 'common-services';
5
+ import {
6
+ noop,
7
+ refersTo,
8
+ type WhookAPISchemaDefinition,
9
+ type WhookRouteDefinition,
11
10
  } from '@whook/whook';
12
- import type {
13
- OAuth2GranterService,
14
- OAuth2AccessTokenService,
15
- OAuth2RefreshTokenService,
11
+ import {
12
+ type OAuth2GranterService,
13
+ type OAuth2RefreshTokenService,
14
+ type OAuth2AccessTokenService,
16
15
  } from '../services/oAuth2Granters.js';
17
- import type { BaseAuthenticationData } from '@whook/authorization';
16
+ import { type WhookAuthenticationData } from '@whook/authorization';
18
17
 
19
18
  /* Architecture Note #2: OAuth2 acknowledge
20
19
  This endpoint is to be used by the authentication server page
21
20
  to acknowlege that the user accepted the client request.
22
21
  */
23
- export const authorizationCodeTokenRequestBodySchema: WhookAPISchemaDefinition =
24
- {
25
- name: 'AuthorizationCodeRequestBody',
26
- schema: {
27
- type: 'object',
28
- description:
29
- 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',
30
- required: ['grant_type'],
31
- properties: {
32
- grant_type: {
33
- type: 'string',
34
- enum: ['authorization_code'],
35
- },
36
- code: {
37
- type: 'string',
38
- },
39
- client_id: {
40
- type: 'string',
41
- },
42
- redirect_uri: {
43
- type: 'string',
44
- pattern: '^https?://',
45
- format: 'uri',
46
- },
22
+ export const authorizationCodeTokenRequestBodySchema = {
23
+ name: 'AuthorizationCodeRequestBody',
24
+ schema: {
25
+ type: 'object',
26
+ description:
27
+ 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',
28
+ required: ['grant_type'],
29
+ properties: {
30
+ grant_type: {
31
+ type: 'string',
32
+ enum: ['authorization_code'],
33
+ },
34
+ code: {
35
+ type: 'string',
36
+ },
37
+ client_id: {
38
+ type: 'string',
39
+ },
40
+ redirect_uri: {
41
+ type: 'string',
42
+ pattern: '^https?://',
43
+ format: 'uri',
47
44
  },
48
45
  },
49
- };
46
+ },
47
+ } as const satisfies WhookAPISchemaDefinition;
50
48
 
51
- export const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {
49
+ export const passwordTokenRequestBodySchema = {
52
50
  name: 'PasswordRequestBody',
53
51
  schema: {
54
52
  type: 'object',
@@ -72,30 +70,29 @@ export const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {
72
70
  },
73
71
  },
74
72
  },
75
- };
73
+ } as const satisfies WhookAPISchemaDefinition;
76
74
 
77
- export const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefinition =
78
- {
79
- name: 'ClientCredentialsRequestBody',
80
- schema: {
81
- type: 'object',
82
- description:
83
- 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',
84
- required: ['grant_type'],
85
- properties: {
86
- grant_type: {
87
- type: 'string',
88
- enum: ['client_credentials'],
89
- },
90
- scope: {
91
- type: 'string',
92
- description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
93
- },
75
+ export const clientCredentialsTokenRequestBodySchema = {
76
+ name: 'ClientCredentialsRequestBody',
77
+ schema: {
78
+ type: 'object',
79
+ description:
80
+ 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',
81
+ required: ['grant_type'],
82
+ properties: {
83
+ grant_type: {
84
+ type: 'string',
85
+ enum: ['client_credentials'],
86
+ },
87
+ scope: {
88
+ type: 'string',
89
+ description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
94
90
  },
95
91
  },
96
- };
92
+ },
93
+ } as const satisfies WhookAPISchemaDefinition;
97
94
 
98
- export const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {
95
+ export const refreshTokenRequestBodySchema = {
99
96
  name: 'RefreshTokenRequestBody',
100
97
  schema: {
101
98
  type: 'object',
@@ -116,9 +113,9 @@ export const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {
116
113
  },
117
114
  },
118
115
  },
119
- };
116
+ } as const satisfies WhookAPISchemaDefinition;
120
117
 
121
- export const tokenBodySchema: WhookAPISchemaDefinition = {
118
+ export const tokenBodySchema = {
122
119
  name: 'TokenRequestBody',
123
120
  schema: {
124
121
  oneOf: [
@@ -127,10 +124,10 @@ export const tokenBodySchema: WhookAPISchemaDefinition = {
127
124
  refersTo(clientCredentialsTokenRequestBodySchema),
128
125
  refersTo(refreshTokenRequestBodySchema),
129
126
  ],
130
- } as OpenAPIV3_1.SchemaObject,
131
- };
127
+ },
128
+ } as const satisfies WhookAPISchemaDefinition;
132
129
 
133
- export const definition: WhookAPIHandlerDefinition = {
130
+ export const definition = {
134
131
  method: 'post',
135
132
  path: '/oauth2/token',
136
133
  operation: {
@@ -210,27 +207,22 @@ export const definition: WhookAPIHandlerDefinition = {
210
207
  },
211
208
  },
212
209
  },
213
- };
210
+ } as const satisfies WhookRouteDefinition;
214
211
 
215
- export default location(autoHandler(postOAuth2Token), import.meta.url);
216
-
217
- async function postOAuth2Token<
218
- AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,
219
- >(
220
- {
221
- oAuth2Granters,
222
- oAuth2AccessToken,
223
- oAuth2RefreshToken,
224
- time = Date.now.bind(Date),
225
- log = noop,
226
- }: {
227
- oAuth2Granters: OAuth2GranterService[];
228
- oAuth2AccessToken: OAuth2AccessTokenService;
229
- oAuth2RefreshToken: OAuth2RefreshTokenService;
230
- log: LogService;
231
- time: TimeService;
232
- },
233
- {
212
+ async function initPostOAuth2Token({
213
+ oAuth2Granters,
214
+ oAuth2AccessToken,
215
+ oAuth2RefreshToken,
216
+ time = Date.now.bind(Date),
217
+ log = noop,
218
+ }: {
219
+ oAuth2Granters: OAuth2GranterService[];
220
+ oAuth2AccessToken: OAuth2AccessTokenService;
221
+ oAuth2RefreshToken: OAuth2RefreshTokenService;
222
+ log: LogService;
223
+ time: TimeService;
224
+ }) {
225
+ return async ({
234
226
  body: { grant_type: grantType, ...grantParameters },
235
227
  authenticationData,
236
228
  }: {
@@ -238,54 +230,57 @@ async function postOAuth2Token<
238
230
  grant_type: string;
239
231
  [name: string]: unknown;
240
232
  };
241
- authenticationData: AUTHENTICATION_DATA;
242
- },
243
- ) {
244
- try {
245
- const granter = oAuth2Granters.find(
246
- (granter) =>
247
- granter.authenticator && granter.authenticator.grantType === grantType,
248
- );
233
+ authenticationData: WhookAuthenticationData;
234
+ }) => {
235
+ try {
236
+ const granter = oAuth2Granters.find(
237
+ (granter) =>
238
+ granter.authenticator &&
239
+ granter.authenticator.grantType === grantType,
240
+ );
249
241
 
250
- if (!granter || !granter.authenticator) {
251
- throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
252
- }
242
+ if (!granter || !granter.authenticator) {
243
+ throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
244
+ }
253
245
 
254
- const newAuthenticationData = await granter.authenticator.authenticate(
255
- camelCaseObjectProperties(grantParameters),
256
- authenticationData,
257
- );
246
+ const newAuthenticationData = await granter.authenticator.authenticate(
247
+ camelCaseObjectProperties(grantParameters),
248
+ authenticationData,
249
+ );
258
250
 
259
- const [
260
- { token: accessToken, expiresAt: accessTokenExpiresAt },
261
- { token: refreshToken, expiresAt: refreshTokenExpiresAt },
262
- ] = await Promise.all([
263
- oAuth2AccessToken.create(authenticationData, newAuthenticationData),
264
- oAuth2RefreshToken.create(authenticationData, newAuthenticationData),
265
- ]);
266
- const currentTime = time();
251
+ const [
252
+ { token: accessToken, expiresAt: accessTokenExpiresAt },
253
+ { token: refreshToken, expiresAt: refreshTokenExpiresAt },
254
+ ] = await Promise.all([
255
+ oAuth2AccessToken.create(authenticationData, newAuthenticationData),
256
+ oAuth2RefreshToken.create(authenticationData, newAuthenticationData),
257
+ ]);
258
+ const currentTime = time();
267
259
 
268
- return {
269
- status: 200,
270
- headers: {},
271
- body: {
272
- access_token: accessToken,
273
- token_type: 'bearer',
274
- expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),
275
- expiration_date: new Date(accessTokenExpiresAt).toISOString(),
276
- refresh_token: refreshToken,
277
- refresh_token_expires_in: Math.ceil(
278
- (refreshTokenExpiresAt - currentTime) / 1000,
279
- ),
280
- refresh_token_expiration_date: new Date(
281
- refreshTokenExpiresAt,
282
- ).toISOString(),
283
- },
284
- };
285
- } catch (err) {
286
- log('debug', '👫 - OAuth2 token issuing error', (err as YError).code);
287
- log('error-stack', printStackTrace(err as Error));
260
+ return {
261
+ status: 200,
262
+ headers: {},
263
+ body: {
264
+ access_token: accessToken,
265
+ token_type: 'bearer',
266
+ expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),
267
+ expiration_date: new Date(accessTokenExpiresAt).toISOString(),
268
+ refresh_token: refreshToken,
269
+ refresh_token_expires_in: Math.ceil(
270
+ (refreshTokenExpiresAt - currentTime) / 1000,
271
+ ),
272
+ refresh_token_expiration_date: new Date(
273
+ refreshTokenExpiresAt,
274
+ ).toISOString(),
275
+ },
276
+ };
277
+ } catch (err) {
278
+ log('debug', '👫 - OAuth2 token issuing error', (err as YError).code);
279
+ log('error-stack', printStackTrace(err as Error));
288
280
 
289
- throw YError.cast(err as Error, 'E_OAUTH2');
290
- }
281
+ throw YError.cast(err as Error, 'E_OAUTH2');
282
+ }
283
+ };
291
284
  }
285
+
286
+ export default location(autoService(initPostOAuth2Token), import.meta.url);
@@ -1,6 +1,6 @@
1
1
  import { describe, test, expect } from '@jest/globals';
2
2
  import initAuthCookies from './authCookies.js';
3
- import type { AuthCookiesConfig } from './authCookies.js';
3
+ import { type AuthCookiesConfig } from './authCookies.js';
4
4
 
5
5
  describe('authCookies', () => {
6
6
  describe('.build()', () => {
@@ -1,15 +1,13 @@
1
1
  import ms from 'ms';
2
2
  import cookie, { type SerializeOptions } from 'cookie';
3
3
  import { autoService, location } from 'knifecycle';
4
- import { type BaseAuthenticationData } from '@whook/authorization';
4
+ import { type WhookAuthenticationData } from '@whook/authorization';
5
5
  import { type Jsonify } from 'type-fest';
6
6
 
7
7
  export const AUTH_API_PREFIX = '/auth';
8
8
 
9
- export type AuthHandlersConfig<
10
- AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,
11
- > = {
12
- ROOT_AUTHENTICATION_DATA: AUTHENTICATION_DATA;
9
+ export type AuthHandlersConfig = {
10
+ ROOT_AUTHENTICATION_DATA: WhookAuthenticationData;
13
11
  };
14
12
 
15
13
  export type AuthCookiesConfig = {
@@ -1,33 +1,28 @@
1
1
  import { autoService, location } from 'knifecycle';
2
2
  import { noop } from '@whook/whook';
3
3
  import { YError } from 'yerror';
4
- import type { LogService } from 'common-services';
5
- import type {
6
- OAuth2GranterService,
7
- CheckApplicationService,
4
+ import { type LogService } from 'common-services';
5
+ import {
6
+ type OAuth2GranterService,
7
+ type CheckApplicationService,
8
8
  } from './oAuth2Granters.js';
9
- import type { BaseAuthenticationData } from '@whook/authorization';
10
- import type { OAuth2Options } from '../services/oAuth2Granters.js';
9
+ import { type WhookAuthenticationData } from '@whook/authorization';
10
+ import { type OAuth2Options } from '../services/oAuth2Granters.js';
11
11
 
12
12
  export type OAuth2ClientCredentialsGranterDependencies = {
13
13
  OAUTH2: OAuth2Options;
14
14
  checkApplication: CheckApplicationService;
15
15
  log?: LogService;
16
16
  };
17
- export type OAuth2ClientCredentialsGranterParameters<
18
- AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,
19
- > = {
17
+ export type OAuth2ClientCredentialsGranterParameters = {
20
18
  username: string;
21
19
  password: string;
22
- scope?: AUTHENTICATION_DATA['scope'];
20
+ scope?: WhookAuthenticationData['scope'];
23
21
  };
24
- export type OAuth2ClientCredentialsGranterService<
25
- AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,
26
- > = OAuth2GranterService<
22
+ export type OAuth2ClientCredentialsGranterService = OAuth2GranterService<
27
23
  Record<string, unknown>,
28
24
  Record<string, unknown>,
29
- OAuth2ClientCredentialsGranterParameters,
30
- AUTHENTICATION_DATA
25
+ OAuth2ClientCredentialsGranterParameters
31
26
  >;
32
27
 
33
28
  export default location(
@@ -1,27 +1,15 @@
1
- import { describe, it, beforeEach, jest, expect } from '@jest/globals';
2
- import { BaseAuthenticationData } from '@whook/authorization';
1
+ import { describe, test, beforeEach, jest, expect } from '@jest/globals';
2
+ import { type WhookAuthenticationData } from '@whook/authorization';
3
3
  import initOAuth2CodeGranter from './oAuth2CodeGranter.js';
4
4
  import {
5
- CheckApplicationService,
6
- OAuth2CodeService,
5
+ type CheckApplicationService,
6
+ type OAuth2CodeService,
7
7
  } from './oAuth2Granters.js';
8
8
 
9
9
  describe('OAuth2CodeGranter', () => {
10
10
  const oAuth2Code = {
11
- create:
12
- jest.fn<
13
- OAuth2CodeService<
14
- BaseAuthenticationData<string, string>,
15
- string
16
- >['create']
17
- >(),
18
- check:
19
- jest.fn<
20
- OAuth2CodeService<
21
- BaseAuthenticationData<string, string>,
22
- string
23
- >['check']
24
- >(),
11
+ create: jest.fn<OAuth2CodeService<string>['create']>(),
12
+ check: jest.fn<OAuth2CodeService<string>['check']>(),
25
13
  };
26
14
  const checkApplication = jest.fn<CheckApplicationService>();
27
15
  const log = jest.fn();
@@ -33,7 +21,7 @@ describe('OAuth2CodeGranter', () => {
33
21
  log.mockReset();
34
22
  });
35
23
 
36
- it('should work with a complete valid flow', async () => {
24
+ test('should work with a complete valid flow', async () => {
37
25
  const oAuth2CodeGranter = await initOAuth2CodeGranter({
38
26
  checkApplication,
39
27
  oAuth2Code,
@@ -51,6 +39,9 @@ describe('OAuth2CodeGranter', () => {
51
39
  redirectURI: 'https://www.example2.com',
52
40
  applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
53
41
  scope: 'user',
42
+ } as WhookAuthenticationData & {
43
+ redirectURI: string;
44
+ [name: string]: unknown;
54
45
  });
55
46
 
56
47
  const authorizerResult = await oAuth2CodeGranter.authorizer?.authorize({
@@ -63,7 +54,7 @@ describe('OAuth2CodeGranter', () => {
63
54
  {
64
55
  applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
65
56
  scope: 'user, admin',
66
- },
57
+ } as WhookAuthenticationData,
67
58
  {
68
59
  clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
69
60
  redirectURI: 'https://www.example.com/oauth2/code',
@@ -81,7 +72,7 @@ describe('OAuth2CodeGranter', () => {
81
72
  {
82
73
  applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
83
74
  scope: 'user',
84
- },
75
+ } as WhookAuthenticationData,
85
76
  );
86
77
 
87
78
  expect({
@@ -1,13 +1,12 @@
1
1
  import { autoService, location } from 'knifecycle';
2
2
  import { noop } from '@whook/whook';
3
3
  import { YError } from 'yerror';
4
- import type { LogService } from 'common-services';
5
- import type {
6
- OAuth2GranterService,
7
- OAuth2CodeService,
8
- CheckApplicationService,
4
+ import { type LogService } from 'common-services';
5
+ import {
6
+ type OAuth2GranterService,
7
+ type OAuth2CodeService,
8
+ type CheckApplicationService,
9
9
  } from './oAuth2Granters.js';
10
- import type { BaseAuthenticationData } from '@whook/authorization';
11
10
 
12
11
  export const CODE_GRANTER_TYPE = 'code';
13
12
 
@@ -21,13 +20,10 @@ export type OAuth2CodeGranterParameters = {
21
20
  redirectURI: string;
22
21
  clientId: string;
23
22
  };
24
- export type OAuth2CodeGranterService<
25
- AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,
26
- > = OAuth2GranterService<
23
+ export type OAuth2CodeGranterService = OAuth2GranterService<
27
24
  Record<string, unknown>,
28
25
  Record<string, unknown>,
29
- OAuth2CodeGranterParameters,
30
- AUTHENTICATION_DATA
26
+ OAuth2CodeGranterParameters
31
27
  >;
32
28
 
33
29
  export default location(autoService(initOAuth2CodeGranter), import.meta.url);
@@ -72,6 +68,8 @@ async function initOAuth2CodeGranter({
72
68
  );
73
69
 
74
70
  return {
71
+ // TODO: check a way to avoid this by adding params
72
+ ...authenticationData,
75
73
  applicationId: clientId,
76
74
  redirectURI,
77
75
  scope,