@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.
- package/README.md +106 -70
- package/dist/handlers/getOAuth2Authorize.d.ts +8 -6
- package/dist/handlers/getOAuth2Authorize.js +122 -165
- package/dist/handlers/getOAuth2Authorize.js.map +1 -1
- package/dist/handlers/getOAuth2Authorize.test.js +117 -103
- package/dist/handlers/getOAuth2Authorize.test.js.map +1 -1
- package/dist/handlers/postAuthLogin.d.ts +3 -3
- package/dist/handlers/postAuthLogin.js +83 -120
- package/dist/handlers/postAuthLogin.js.map +1 -1
- package/dist/handlers/postAuthLogin.test.js +42 -44
- package/dist/handlers/postAuthLogin.test.js.map +1 -1
- package/dist/handlers/postAuthLogout.d.ts +1 -1
- package/dist/handlers/postAuthLogout.js +26 -42
- package/dist/handlers/postAuthLogout.js.map +1 -1
- package/dist/handlers/postAuthLogout.test.js +19 -21
- package/dist/handlers/postAuthLogout.test.js.map +1 -1
- package/dist/handlers/postAuthRefresh.d.ts +4 -4
- package/dist/handlers/postAuthRefresh.js +93 -131
- package/dist/handlers/postAuthRefresh.js.map +1 -1
- package/dist/handlers/postAuthRefresh.test.js +47 -49
- package/dist/handlers/postAuthRefresh.test.js.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.d.ts +11 -8
- package/dist/handlers/postOAuth2Acknowledge.js +119 -151
- package/dist/handlers/postOAuth2Acknowledge.js.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.test.js +139 -125
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/handlers/postOAuth2Token.d.ts +4 -4
- package/dist/handlers/postOAuth2Token.js +200 -232
- package/dist/handlers/postOAuth2Token.js.map +1 -1
- package/dist/handlers/postOAuth2Token.test.js +156 -153
- package/dist/handlers/postOAuth2Token.test.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.js +14 -229
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +697 -620
- package/dist/index.test.js.map +1 -1
- package/dist/services/authCookies.d.ts +8 -4
- package/dist/services/authCookies.js +40 -71
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js +57 -62
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +2 -2
- package/dist/services/oAuth2ClientCredentialsGranter.js +34 -52
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.d.ts +1 -1
- package/dist/services/oAuth2CodeGranter.js +66 -109
- package/dist/services/oAuth2CodeGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.js +65 -64
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2Granters.d.ts +22 -19
- package/dist/services/oAuth2Granters.js +131 -138
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.d.ts +1 -1
- package/dist/services/oAuth2PasswordGranter.js +27 -52
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.js +34 -58
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2TokenGranter.d.ts +1 -1
- package/dist/services/oAuth2TokenGranter.js +50 -86
- package/dist/services/oAuth2TokenGranter.js.map +1 -1
- package/package.json +54 -96
- package/src/__snapshots__/index.test.ts.snap +23 -22
- package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +1 -1
- package/src/handlers/getOAuth2Authorize.test.ts +49 -13
- package/src/handlers/getOAuth2Authorize.ts +17 -16
- package/src/handlers/postAuthLogin.test.ts +9 -5
- package/src/handlers/postAuthLogin.ts +8 -7
- package/src/handlers/postAuthLogout.test.ts +8 -4
- package/src/handlers/postAuthLogout.ts +2 -2
- package/src/handlers/postAuthRefresh.test.ts +10 -6
- package/src/handlers/postAuthRefresh.ts +8 -7
- package/src/handlers/postOAuth2Acknowledge.test.ts +83 -35
- package/src/handlers/postOAuth2Acknowledge.ts +48 -30
- package/src/handlers/postOAuth2Token.test.ts +79 -19
- package/src/handlers/postOAuth2Token.ts +7 -7
- package/src/index.test.ts +116 -72
- package/src/index.ts +21 -19
- package/src/services/authCookies.test.ts +2 -2
- package/src/services/authCookies.ts +10 -5
- package/src/services/oAuth2ClientCredentialsGranter.ts +28 -24
- package/src/services/oAuth2CodeGranter.test.ts +42 -18
- package/src/services/oAuth2CodeGranter.ts +68 -62
- package/src/services/oAuth2Granters.ts +59 -29
- package/src/services/oAuth2PasswordGranter.ts +25 -24
- package/src/services/oAuth2RefreshTokenGranter.ts +30 -26
- package/src/services/oAuth2TokenGranter.ts +45 -43
- package/dist/handlers/getOAuth2Authorize.mjs +0 -160
- package/dist/handlers/getOAuth2Authorize.mjs.map +0 -1
- package/dist/handlers/getOAuth2Authorize.test.mjs +0 -114
- package/dist/handlers/getOAuth2Authorize.test.mjs.map +0 -1
- package/dist/handlers/postAuthLogin.mjs +0 -108
- package/dist/handlers/postAuthLogin.mjs.map +0 -1
- package/dist/handlers/postAuthLogin.test.mjs +0 -85
- package/dist/handlers/postAuthLogin.test.mjs.map +0 -1
- package/dist/handlers/postAuthLogout.mjs +0 -33
- package/dist/handlers/postAuthLogout.mjs.map +0 -1
- package/dist/handlers/postAuthLogout.test.mjs +0 -30
- package/dist/handlers/postAuthLogout.test.mjs.map +0 -1
- package/dist/handlers/postAuthRefresh.mjs +0 -121
- package/dist/handlers/postAuthRefresh.mjs.map +0 -1
- package/dist/handlers/postAuthRefresh.test.mjs +0 -94
- package/dist/handlers/postAuthRefresh.test.mjs.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.mjs +0 -150
- package/dist/handlers/postOAuth2Acknowledge.mjs.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.test.mjs +0 -140
- package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +0 -1
- package/dist/handlers/postOAuth2Token.mjs +0 -231
- package/dist/handlers/postOAuth2Token.mjs.map +0 -1
- package/dist/handlers/postOAuth2Token.test.mjs +0 -160
- package/dist/handlers/postOAuth2Token.test.mjs.map +0 -1
- package/dist/index.mjs +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/index.test.mjs +0 -748
- package/dist/index.test.mjs.map +0 -1
- package/dist/services/authCookies.mjs +0 -58
- package/dist/services/authCookies.mjs.map +0 -1
- package/dist/services/authCookies.test.mjs +0 -77
- package/dist/services/authCookies.test.mjs.map +0 -1
- package/dist/services/oAuth2ClientCredentialsGranter.mjs +0 -41
- package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +0 -1
- package/dist/services/oAuth2CodeGranter.mjs +0 -98
- package/dist/services/oAuth2CodeGranter.mjs.map +0 -1
- package/dist/services/oAuth2CodeGranter.test.mjs +0 -81
- package/dist/services/oAuth2CodeGranter.test.mjs.map +0 -1
- package/dist/services/oAuth2Granters.mjs +0 -127
- package/dist/services/oAuth2Granters.mjs.map +0 -1
- package/dist/services/oAuth2PasswordGranter.mjs +0 -40
- package/dist/services/oAuth2PasswordGranter.mjs.map +0 -1
- package/dist/services/oAuth2RefreshTokenGranter.mjs +0 -47
- package/dist/services/oAuth2RefreshTokenGranter.mjs.map +0 -1
- package/dist/services/oAuth2TokenGranter.mjs +0 -78
- package/dist/services/oAuth2TokenGranter.mjs.map +0 -1
package/src/index.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
1
2
|
import {
|
|
2
3
|
runServer,
|
|
3
4
|
prepareServer,
|
|
@@ -6,11 +7,12 @@ import {
|
|
|
6
7
|
} from '@whook/whook';
|
|
7
8
|
import {
|
|
8
9
|
AUTHORIZATION_ERRORS_DESCRIPTORS,
|
|
10
|
+
BaseAuthenticationData,
|
|
9
11
|
wrapHandlerWithAuthorization,
|
|
10
12
|
} from '@whook/authorization';
|
|
11
13
|
import { constant, initializer } from 'knifecycle';
|
|
12
|
-
import axios from 'axios';
|
|
13
|
-
import YError from 'yerror';
|
|
14
|
+
import { default as axios } from 'axios';
|
|
15
|
+
import { YError } from 'yerror';
|
|
14
16
|
import {
|
|
15
17
|
BEARER as BEARER_MECHANISM,
|
|
16
18
|
BASIC as BASIC_MECHANISM,
|
|
@@ -39,20 +41,33 @@ import {
|
|
|
39
41
|
postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
40
42
|
postOAuth2TokenTokenBodySchema,
|
|
41
43
|
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
42
|
-
} from '.';
|
|
43
|
-
import type {
|
|
44
|
-
|
|
44
|
+
} from './index.js';
|
|
45
|
+
import type {
|
|
46
|
+
OAuth2Options,
|
|
47
|
+
CheckApplicationService,
|
|
48
|
+
OAuth2PasswordService,
|
|
49
|
+
OAuth2CodeService,
|
|
50
|
+
OAuth2RefreshTokenService,
|
|
51
|
+
OAuth2AccessTokenService,
|
|
52
|
+
} from './index.js';
|
|
53
|
+
import type { Knifecycle } from 'knifecycle';
|
|
45
54
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
55
|
+
import type { Logger } from 'common-services';
|
|
56
|
+
import type { AuthenticationService } from '@whook/authorization';
|
|
57
|
+
|
|
58
|
+
type CustomAuthenticationData = BaseAuthenticationData & {
|
|
59
|
+
userId: string;
|
|
60
|
+
};
|
|
46
61
|
|
|
47
62
|
describe('OAuth2 server', () => {
|
|
48
63
|
const BASE_PATH = '/v1';
|
|
49
64
|
const PORT = 4444;
|
|
50
65
|
const HOST = 'localhost';
|
|
51
66
|
const logger = {
|
|
52
|
-
|
|
53
|
-
error: jest.fn(),
|
|
67
|
+
output: jest.fn<Logger['output']>(),
|
|
68
|
+
error: jest.fn<Logger['error']>(),
|
|
69
|
+
debug: jest.fn<Logger['debug']>(),
|
|
54
70
|
};
|
|
55
|
-
const debug = jest.fn();
|
|
56
71
|
const time = jest.fn();
|
|
57
72
|
const $autoload = jest.fn();
|
|
58
73
|
|
|
@@ -133,13 +148,30 @@ describe('OAuth2 server', () => {
|
|
|
133
148
|
const OAUTH2: OAuth2Options = {
|
|
134
149
|
authenticateURL: 'https://auth.example.com/sign_in',
|
|
135
150
|
};
|
|
136
|
-
const authentication = {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
|
|
151
|
+
const authentication = {
|
|
152
|
+
check:
|
|
153
|
+
jest.fn<AuthenticationService<any, CustomAuthenticationData>['check']>(),
|
|
154
|
+
};
|
|
155
|
+
const checkApplication = jest.fn<CheckApplicationService>();
|
|
156
|
+
const oAuth2AccessToken = {
|
|
157
|
+
create:
|
|
158
|
+
jest.fn<OAuth2AccessTokenService<CustomAuthenticationData>['create']>(),
|
|
159
|
+
check:
|
|
160
|
+
jest.fn<OAuth2AccessTokenService<CustomAuthenticationData>['check']>(),
|
|
161
|
+
};
|
|
162
|
+
const oAuth2RefreshToken = {
|
|
163
|
+
create:
|
|
164
|
+
jest.fn<OAuth2RefreshTokenService<CustomAuthenticationData>['create']>(),
|
|
165
|
+
check:
|
|
166
|
+
jest.fn<OAuth2RefreshTokenService<CustomAuthenticationData>['check']>(),
|
|
167
|
+
};
|
|
168
|
+
const oAuth2Code = {
|
|
169
|
+
create: jest.fn<OAuth2CodeService<CustomAuthenticationData>['create']>(),
|
|
170
|
+
check: jest.fn<OAuth2CodeService<CustomAuthenticationData>['check']>(),
|
|
171
|
+
};
|
|
172
|
+
const oAuth2Password = {
|
|
173
|
+
check: jest.fn<OAuth2PasswordService<CustomAuthenticationData>['check']>(),
|
|
174
|
+
};
|
|
143
175
|
|
|
144
176
|
let $instance;
|
|
145
177
|
|
|
@@ -165,9 +197,8 @@ describe('OAuth2 server', () => {
|
|
|
165
197
|
$.register(constant('DEBUG_NODE_ENVS', []));
|
|
166
198
|
$.register(constant('NODE_ENVS', ['test']));
|
|
167
199
|
$.register(constant('MECHANISMS', [BEARER_MECHANISM, BASIC_MECHANISM]));
|
|
168
|
-
$.register(constant('logger', logger));
|
|
200
|
+
$.register(constant('logger', logger as Logger));
|
|
169
201
|
$.register(constant('time', time));
|
|
170
|
-
$.register(constant('debug', debug));
|
|
171
202
|
|
|
172
203
|
// OAuth2 Specifics
|
|
173
204
|
$.register(constant('OAUTH2', OAUTH2));
|
|
@@ -197,13 +228,12 @@ describe('OAuth2 server', () => {
|
|
|
197
228
|
$.register(constant('checkApplication', checkApplication));
|
|
198
229
|
$.register(constant('oAuth2AccessToken', oAuth2AccessToken));
|
|
199
230
|
$.register(constant('oAuth2RefreshToken', oAuth2RefreshToken));
|
|
200
|
-
$.register(constant('oAuth2ClientCredentials', oAuth2ClientCredentials));
|
|
201
231
|
$.register(constant('oAuth2Code', oAuth2Code));
|
|
202
232
|
$.register(constant('oAuth2Password', oAuth2Password));
|
|
203
233
|
[
|
|
204
234
|
initGetOAuth2Authorize,
|
|
205
|
-
wrapHandlerWithAuthorization(initPostOAuth2Acknowledge),
|
|
206
|
-
wrapHandlerWithAuthorization(initPostOAuth2Token),
|
|
235
|
+
wrapHandlerWithAuthorization(initPostOAuth2Acknowledge as any),
|
|
236
|
+
wrapHandlerWithAuthorization(initPostOAuth2Token as any),
|
|
207
237
|
initOAuth2Granters,
|
|
208
238
|
initOAuth2ClientCredentialsGranter,
|
|
209
239
|
initOAuth2CodeGranter,
|
|
@@ -222,7 +252,7 @@ describe('OAuth2 server', () => {
|
|
|
222
252
|
|
|
223
253
|
beforeAll(async () => {
|
|
224
254
|
const { $instance: _instance } = await runServer<{
|
|
225
|
-
$instance: Knifecycle
|
|
255
|
+
$instance: Knifecycle;
|
|
226
256
|
}>(prepareEnvironment, prepareServer, [
|
|
227
257
|
'$instance',
|
|
228
258
|
'httpServer',
|
|
@@ -236,9 +266,9 @@ describe('OAuth2 server', () => {
|
|
|
236
266
|
});
|
|
237
267
|
|
|
238
268
|
beforeEach(() => {
|
|
239
|
-
logger.
|
|
269
|
+
logger.output.mockReset();
|
|
240
270
|
logger.error.mockReset();
|
|
241
|
-
debug.mockReset();
|
|
271
|
+
logger.debug.mockReset();
|
|
242
272
|
time.mockReset();
|
|
243
273
|
$autoload.mockClear();
|
|
244
274
|
[
|
|
@@ -246,7 +276,6 @@ describe('OAuth2 server', () => {
|
|
|
246
276
|
oAuth2AccessToken.check,
|
|
247
277
|
oAuth2RefreshToken.create,
|
|
248
278
|
oAuth2RefreshToken.check,
|
|
249
|
-
oAuth2ClientCredentials.check,
|
|
250
279
|
oAuth2Code.check,
|
|
251
280
|
oAuth2Code.create,
|
|
252
281
|
oAuth2Password.check,
|
|
@@ -261,24 +290,27 @@ describe('OAuth2 server', () => {
|
|
|
261
290
|
[
|
|
262
291
|
oAuth2AccessToken.check,
|
|
263
292
|
oAuth2RefreshToken.check,
|
|
264
|
-
oAuth2ClientCredentials.check,
|
|
265
293
|
oAuth2Code.check,
|
|
266
294
|
oAuth2Code.create,
|
|
267
295
|
oAuth2RefreshToken.check,
|
|
268
|
-
].forEach((mock) =>
|
|
296
|
+
].forEach((mock: any) =>
|
|
269
297
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
270
298
|
);
|
|
271
299
|
authentication.check.mockResolvedValueOnce({
|
|
272
300
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
273
301
|
scope: 'user,oauth',
|
|
302
|
+
userId: '2',
|
|
303
|
+
});
|
|
304
|
+
checkApplication.mockResolvedValueOnce({
|
|
305
|
+
type: 'code',
|
|
306
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
307
|
+
scope: 'user,oauth',
|
|
308
|
+
redirectURI: 'http://redirect.example.com/yolo',
|
|
274
309
|
});
|
|
275
|
-
checkApplication.mockResolvedValueOnce(undefined);
|
|
276
310
|
oAuth2Password.check.mockResolvedValueOnce({
|
|
277
311
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
278
312
|
scope: 'user,auth',
|
|
279
|
-
|
|
280
|
-
userId: 1,
|
|
281
|
-
},
|
|
313
|
+
userId: '1',
|
|
282
314
|
});
|
|
283
315
|
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
284
316
|
token: 'an_access_token',
|
|
@@ -313,6 +345,7 @@ describe('OAuth2 server', () => {
|
|
|
313
345
|
// Erasing the Date header that may be added by Axios :/
|
|
314
346
|
date: undefined,
|
|
315
347
|
},
|
|
348
|
+
|
|
316
349
|
data,
|
|
317
350
|
}).toMatchInlineSnapshot(`
|
|
318
351
|
Object {
|
|
@@ -331,7 +364,7 @@ describe('OAuth2 server', () => {
|
|
|
331
364
|
"date": undefined,
|
|
332
365
|
"transaction-id": "0",
|
|
333
366
|
"transfer-encoding": "chunked",
|
|
334
|
-
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\"}",
|
|
367
|
+
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\",\\"userId\\":\\"2\\"}",
|
|
335
368
|
},
|
|
336
369
|
"status": 200,
|
|
337
370
|
}
|
|
@@ -343,8 +376,6 @@ describe('OAuth2 server', () => {
|
|
|
343
376
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
344
377
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
345
378
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
346
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
347
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
348
379
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
349
380
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
350
381
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -357,7 +388,6 @@ describe('OAuth2 server', () => {
|
|
|
357
388
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
358
389
|
[
|
|
359
390
|
oAuth2AccessToken.check,
|
|
360
|
-
oAuth2ClientCredentials.check,
|
|
361
391
|
oAuth2Code.check,
|
|
362
392
|
oAuth2Code.create,
|
|
363
393
|
oAuth2Password.check,
|
|
@@ -367,14 +397,18 @@ describe('OAuth2 server', () => {
|
|
|
367
397
|
authentication.check.mockResolvedValueOnce({
|
|
368
398
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
369
399
|
scope: 'user,oauth',
|
|
400
|
+
userId: '2',
|
|
401
|
+
});
|
|
402
|
+
checkApplication.mockResolvedValueOnce({
|
|
403
|
+
type: 'code',
|
|
404
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
405
|
+
scope: 'user,oauth',
|
|
406
|
+
redirectURI: 'http://redirect.example.com/yolo',
|
|
370
407
|
});
|
|
371
|
-
checkApplication.mockResolvedValueOnce(undefined);
|
|
372
408
|
oAuth2RefreshToken.check.mockResolvedValueOnce({
|
|
373
409
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
374
410
|
scope: 'user,auth',
|
|
375
|
-
|
|
376
|
-
userId: 1,
|
|
377
|
-
},
|
|
411
|
+
userId: '1',
|
|
378
412
|
});
|
|
379
413
|
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
380
414
|
token: 'an_access_token',
|
|
@@ -408,6 +442,7 @@ describe('OAuth2 server', () => {
|
|
|
408
442
|
// Erasing the Date header that may be added by Axios :/
|
|
409
443
|
date: undefined,
|
|
410
444
|
},
|
|
445
|
+
|
|
411
446
|
data,
|
|
412
447
|
}).toMatchInlineSnapshot(`
|
|
413
448
|
Object {
|
|
@@ -426,7 +461,7 @@ describe('OAuth2 server', () => {
|
|
|
426
461
|
"date": undefined,
|
|
427
462
|
"transaction-id": "1",
|
|
428
463
|
"transfer-encoding": "chunked",
|
|
429
|
-
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\"}",
|
|
464
|
+
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\",\\"userId\\":\\"2\\"}",
|
|
430
465
|
},
|
|
431
466
|
"status": 200,
|
|
432
467
|
}
|
|
@@ -438,8 +473,6 @@ describe('OAuth2 server', () => {
|
|
|
438
473
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
439
474
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
440
475
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
441
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
442
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
443
476
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
444
477
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
445
478
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -462,14 +495,13 @@ describe('OAuth2 server', () => {
|
|
|
462
495
|
authentication.check.mockResolvedValueOnce({
|
|
463
496
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
464
497
|
scope: 'user,oauth',
|
|
498
|
+
userId: '2',
|
|
465
499
|
});
|
|
466
|
-
checkApplication.mockResolvedValueOnce(
|
|
467
|
-
|
|
500
|
+
checkApplication.mockResolvedValueOnce({
|
|
501
|
+
type: 'code',
|
|
468
502
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
469
|
-
scope: 'user,
|
|
470
|
-
|
|
471
|
-
userId: 1,
|
|
472
|
-
},
|
|
503
|
+
scope: 'user,oauth',
|
|
504
|
+
redirectURI: 'http://redirect.example.com/yolo',
|
|
473
505
|
});
|
|
474
506
|
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
475
507
|
token: 'an_access_token',
|
|
@@ -502,6 +534,7 @@ describe('OAuth2 server', () => {
|
|
|
502
534
|
// Erasing the Date header that may be added by Axios :/
|
|
503
535
|
date: undefined,
|
|
504
536
|
},
|
|
537
|
+
|
|
505
538
|
data,
|
|
506
539
|
}).toMatchInlineSnapshot(`
|
|
507
540
|
Object {
|
|
@@ -520,7 +553,7 @@ describe('OAuth2 server', () => {
|
|
|
520
553
|
"date": undefined,
|
|
521
554
|
"transaction-id": "2",
|
|
522
555
|
"transfer-encoding": "chunked",
|
|
523
|
-
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\"}",
|
|
556
|
+
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\",\\"userId\\":\\"2\\"}",
|
|
524
557
|
},
|
|
525
558
|
"status": 200,
|
|
526
559
|
}
|
|
@@ -532,8 +565,6 @@ describe('OAuth2 server', () => {
|
|
|
532
565
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
533
566
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
534
567
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
535
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
536
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
537
568
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
538
569
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
539
570
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -552,12 +583,14 @@ describe('OAuth2 server', () => {
|
|
|
552
583
|
oAuth2RefreshToken.create,
|
|
553
584
|
oAuth2Code.check,
|
|
554
585
|
oAuth2Code.create,
|
|
555
|
-
oAuth2ClientCredentials.check,
|
|
556
586
|
oAuth2Password.check,
|
|
557
587
|
].forEach((mock) =>
|
|
558
588
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
559
589
|
);
|
|
560
590
|
checkApplication.mockResolvedValueOnce({
|
|
591
|
+
type: 'code',
|
|
592
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
593
|
+
scope: 'user,oauth',
|
|
561
594
|
redirectURI:
|
|
562
595
|
'https://example.com/oauth2/callback?a_param=a_param_value',
|
|
563
596
|
});
|
|
@@ -605,8 +638,6 @@ describe('OAuth2 server', () => {
|
|
|
605
638
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
606
639
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
607
640
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
608
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
609
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
610
641
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
611
642
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
612
643
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -621,7 +652,6 @@ describe('OAuth2 server', () => {
|
|
|
621
652
|
oAuth2RefreshToken.check,
|
|
622
653
|
oAuth2RefreshToken.create,
|
|
623
654
|
oAuth2Code.check,
|
|
624
|
-
oAuth2ClientCredentials.check,
|
|
625
655
|
oAuth2Password.check,
|
|
626
656
|
].forEach((mock) =>
|
|
627
657
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
@@ -629,10 +659,13 @@ describe('OAuth2 server', () => {
|
|
|
629
659
|
authentication.check.mockResolvedValueOnce({
|
|
630
660
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
631
661
|
scope: 'user,oauth',
|
|
662
|
+
userId: '2',
|
|
632
663
|
});
|
|
633
664
|
oAuth2Code.create.mockResolvedValueOnce('a_code');
|
|
634
|
-
checkApplication.mockResolvedValueOnce(undefined);
|
|
635
665
|
checkApplication.mockResolvedValueOnce({
|
|
666
|
+
type: 'code',
|
|
667
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
668
|
+
scope: 'user,oauth',
|
|
636
669
|
redirectURI: 'http://redirect.example.com/yolo',
|
|
637
670
|
});
|
|
638
671
|
|
|
@@ -661,6 +694,7 @@ describe('OAuth2 server', () => {
|
|
|
661
694
|
// Erasing the Date header that may be added by Axios :/
|
|
662
695
|
date: undefined,
|
|
663
696
|
},
|
|
697
|
+
|
|
664
698
|
data,
|
|
665
699
|
}).toMatchInlineSnapshot(`
|
|
666
700
|
Object {
|
|
@@ -671,7 +705,7 @@ describe('OAuth2 server', () => {
|
|
|
671
705
|
"location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo%3Fa_param%3Da_value&code=a_code",
|
|
672
706
|
"transaction-id": "4",
|
|
673
707
|
"transfer-encoding": "chunked",
|
|
674
|
-
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\"}",
|
|
708
|
+
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\",\\"userId\\":\\"2\\"}",
|
|
675
709
|
},
|
|
676
710
|
"status": 302,
|
|
677
711
|
}
|
|
@@ -683,8 +717,6 @@ describe('OAuth2 server', () => {
|
|
|
683
717
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
684
718
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
685
719
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
686
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
687
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
688
720
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
689
721
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
690
722
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -696,7 +728,6 @@ describe('OAuth2 server', () => {
|
|
|
696
728
|
[
|
|
697
729
|
oAuth2AccessToken.check,
|
|
698
730
|
oAuth2RefreshToken.check,
|
|
699
|
-
oAuth2ClientCredentials.check,
|
|
700
731
|
oAuth2Password.check,
|
|
701
732
|
].forEach((mock) =>
|
|
702
733
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
@@ -704,12 +735,19 @@ describe('OAuth2 server', () => {
|
|
|
704
735
|
authentication.check.mockResolvedValueOnce({
|
|
705
736
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
706
737
|
scope: 'user,oauth',
|
|
738
|
+
userId: '2',
|
|
739
|
+
});
|
|
740
|
+
checkApplication.mockResolvedValueOnce({
|
|
741
|
+
type: 'code',
|
|
742
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
743
|
+
scope: 'user,oauth',
|
|
744
|
+
redirectURI: 'http://redirect.example.com/yolo',
|
|
707
745
|
});
|
|
708
|
-
checkApplication.mockResolvedValueOnce(undefined);
|
|
709
746
|
oAuth2Code.check.mockResolvedValueOnce({
|
|
710
747
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
711
748
|
scope: 'user,auth',
|
|
712
|
-
userId: 1,
|
|
749
|
+
userId: '1',
|
|
750
|
+
redirectURI: 'http://redirect.example.com/yolo',
|
|
713
751
|
});
|
|
714
752
|
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
715
753
|
token: 'an_access_token',
|
|
@@ -743,6 +781,7 @@ describe('OAuth2 server', () => {
|
|
|
743
781
|
// Erasing the Date header that may be added by Axios :/
|
|
744
782
|
date: undefined,
|
|
745
783
|
},
|
|
784
|
+
|
|
746
785
|
data,
|
|
747
786
|
}).toMatchInlineSnapshot(`
|
|
748
787
|
Object {
|
|
@@ -761,7 +800,7 @@ describe('OAuth2 server', () => {
|
|
|
761
800
|
"date": undefined,
|
|
762
801
|
"transaction-id": "5",
|
|
763
802
|
"transfer-encoding": "chunked",
|
|
764
|
-
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\"}",
|
|
803
|
+
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\",\\"userId\\":\\"2\\"}",
|
|
765
804
|
},
|
|
766
805
|
"status": 200,
|
|
767
806
|
}
|
|
@@ -773,8 +812,6 @@ describe('OAuth2 server', () => {
|
|
|
773
812
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
774
813
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
775
814
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
776
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
777
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
778
815
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
779
816
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
780
817
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -793,12 +830,14 @@ describe('OAuth2 server', () => {
|
|
|
793
830
|
oAuth2RefreshToken.create,
|
|
794
831
|
oAuth2Code.check,
|
|
795
832
|
oAuth2Code.create,
|
|
796
|
-
oAuth2ClientCredentials.check,
|
|
797
833
|
oAuth2Password.check,
|
|
798
834
|
].forEach((mock) =>
|
|
799
835
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
800
836
|
);
|
|
801
837
|
checkApplication.mockResolvedValueOnce({
|
|
838
|
+
type: 'implicit',
|
|
839
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
840
|
+
scope: 'user,oauth',
|
|
802
841
|
redirectURI: 'http://redirect.example.com/yolo',
|
|
803
842
|
});
|
|
804
843
|
|
|
@@ -844,8 +883,6 @@ describe('OAuth2 server', () => {
|
|
|
844
883
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
845
884
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
846
885
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
847
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
848
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
849
886
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
850
887
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
851
888
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
@@ -860,7 +897,6 @@ describe('OAuth2 server', () => {
|
|
|
860
897
|
oAuth2RefreshToken.create,
|
|
861
898
|
oAuth2Code.check,
|
|
862
899
|
oAuth2Code.create,
|
|
863
|
-
oAuth2ClientCredentials.check,
|
|
864
900
|
oAuth2Password.check,
|
|
865
901
|
].forEach((mock) =>
|
|
866
902
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
@@ -868,13 +904,22 @@ describe('OAuth2 server', () => {
|
|
|
868
904
|
authentication.check.mockResolvedValueOnce({
|
|
869
905
|
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
870
906
|
scope: 'user,oauth',
|
|
907
|
+
userId: '2',
|
|
871
908
|
});
|
|
872
909
|
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
873
910
|
token: 'an_access_token',
|
|
874
911
|
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
875
912
|
});
|
|
876
|
-
checkApplication.mockResolvedValueOnce(undefined);
|
|
877
913
|
checkApplication.mockResolvedValueOnce({
|
|
914
|
+
type: 'implicit',
|
|
915
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
916
|
+
scope: 'user,oauth',
|
|
917
|
+
redirectURI: 'http://redirect.example.com/yolo',
|
|
918
|
+
});
|
|
919
|
+
checkApplication.mockResolvedValueOnce({
|
|
920
|
+
type: 'implicit',
|
|
921
|
+
applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
|
|
922
|
+
scope: 'user,oauth',
|
|
878
923
|
redirectURI: 'http://redirect.example.com/yolo',
|
|
879
924
|
});
|
|
880
925
|
|
|
@@ -903,6 +948,7 @@ describe('OAuth2 server', () => {
|
|
|
903
948
|
// Erasing the Date header that may be added by Axios :/
|
|
904
949
|
date: undefined,
|
|
905
950
|
},
|
|
951
|
+
|
|
906
952
|
data,
|
|
907
953
|
}).toMatchInlineSnapshot(`
|
|
908
954
|
Object {
|
|
@@ -913,7 +959,7 @@ describe('OAuth2 server', () => {
|
|
|
913
959
|
"location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&access_token=an_access_token&token_type=bearer&expires_in=86400",
|
|
914
960
|
"transaction-id": "7",
|
|
915
961
|
"transfer-encoding": "chunked",
|
|
916
|
-
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\"}",
|
|
962
|
+
"x-authenticated": "{\\"applicationId\\":\\"acdc41ce-acdc-41ce-acdc-41ceacdc41ce\\",\\"scope\\":\\"user,oauth\\",\\"userId\\":\\"2\\"}",
|
|
917
963
|
},
|
|
918
964
|
"status": 302,
|
|
919
965
|
}
|
|
@@ -925,8 +971,6 @@ describe('OAuth2 server', () => {
|
|
|
925
971
|
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
926
972
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
927
973
|
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
928
|
-
oAuth2ClientCredentialsCheckCalls:
|
|
929
|
-
oAuth2ClientCredentials.check.mock.calls,
|
|
930
974
|
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
931
975
|
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
932
976
|
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
package/src/index.ts
CHANGED
|
@@ -5,10 +5,10 @@ import initGetOAuth2Authorize, {
|
|
|
5
5
|
redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,
|
|
6
6
|
scopeParameter as getOAuth2AuthorizeScopeParameter,
|
|
7
7
|
stateParameter as getOAuth2AuthorizeStateParameter,
|
|
8
|
-
} from './handlers/getOAuth2Authorize';
|
|
8
|
+
} from './handlers/getOAuth2Authorize.js';
|
|
9
9
|
import initPostOAuth2Acknowledge, {
|
|
10
10
|
definition as postOAuth2AcknowledgeDefinition,
|
|
11
|
-
} from './handlers/postOAuth2Acknowledge';
|
|
11
|
+
} from './handlers/postOAuth2Acknowledge.js';
|
|
12
12
|
import initPostOAuth2Token, {
|
|
13
13
|
definition as postOAuth2TokenDefinition,
|
|
14
14
|
authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
|
|
@@ -16,15 +16,15 @@ import initPostOAuth2Token, {
|
|
|
16
16
|
clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
17
17
|
refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
18
18
|
tokenBodySchema as postOAuth2TokenTokenBodySchema,
|
|
19
|
-
} from './handlers/postOAuth2Token';
|
|
19
|
+
} from './handlers/postOAuth2Token.js';
|
|
20
20
|
import initOAuth2Granters, {
|
|
21
21
|
OAUTH2_ERRORS_DESCRIPTORS,
|
|
22
|
-
} from './services/oAuth2Granters';
|
|
23
|
-
import initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';
|
|
24
|
-
import initOAuth2CodeGranter from './services/oAuth2CodeGranter';
|
|
25
|
-
import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';
|
|
26
|
-
import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';
|
|
27
|
-
import initOAuth2TokenGranter from './services/oAuth2TokenGranter';
|
|
22
|
+
} from './services/oAuth2Granters.js';
|
|
23
|
+
import initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter.js';
|
|
24
|
+
import initOAuth2CodeGranter from './services/oAuth2CodeGranter.js';
|
|
25
|
+
import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter.js';
|
|
26
|
+
import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter.js';
|
|
27
|
+
import initOAuth2TokenGranter from './services/oAuth2TokenGranter.js';
|
|
28
28
|
import type {
|
|
29
29
|
OAuth2CodeService,
|
|
30
30
|
OAuth2PasswordService,
|
|
@@ -34,26 +34,27 @@ import type {
|
|
|
34
34
|
OAuth2GranterService,
|
|
35
35
|
OAuth2Options,
|
|
36
36
|
OAuth2Config,
|
|
37
|
-
} from './services/oAuth2Granters';
|
|
37
|
+
} from './services/oAuth2Granters.js';
|
|
38
38
|
import initPostAuthLogin, {
|
|
39
39
|
definition as postAuthLoginDefinition,
|
|
40
|
-
} from './handlers/postAuthLogin';
|
|
40
|
+
} from './handlers/postAuthLogin.js';
|
|
41
41
|
import initPostAuthLogout, {
|
|
42
42
|
definition as postAuthLogoutDefinition,
|
|
43
|
-
} from './handlers/postAuthLogout';
|
|
43
|
+
} from './handlers/postAuthLogout.js';
|
|
44
44
|
import initPostAuthRefresh, {
|
|
45
45
|
authCookieHeaderParameter,
|
|
46
46
|
definition as postAuthRefreshDefinition,
|
|
47
|
-
} from './handlers/postAuthRefresh';
|
|
47
|
+
} from './handlers/postAuthRefresh.js';
|
|
48
48
|
import initAuthCookiesService, {
|
|
49
49
|
AUTH_API_PREFIX,
|
|
50
|
-
} from './services/authCookies';
|
|
50
|
+
} from './services/authCookies.js';
|
|
51
51
|
import type {
|
|
52
|
-
|
|
53
|
-
AuthCookiesService,
|
|
52
|
+
AuthCookiesEnv,
|
|
54
53
|
AuthCookiesConfig,
|
|
54
|
+
AuthCookiesService,
|
|
55
55
|
AuthCookiesData,
|
|
56
|
-
|
|
56
|
+
AuthHandlersConfig,
|
|
57
|
+
} from './services/authCookies.js';
|
|
57
58
|
|
|
58
59
|
export type {
|
|
59
60
|
OAuth2CodeService,
|
|
@@ -64,10 +65,11 @@ export type {
|
|
|
64
65
|
OAuth2GranterService,
|
|
65
66
|
OAuth2Options,
|
|
66
67
|
OAuth2Config,
|
|
67
|
-
|
|
68
|
-
AuthCookiesService,
|
|
68
|
+
AuthCookiesEnv,
|
|
69
69
|
AuthCookiesConfig,
|
|
70
|
+
AuthCookiesService,
|
|
70
71
|
AuthCookiesData,
|
|
72
|
+
AuthHandlersConfig,
|
|
71
73
|
};
|
|
72
74
|
export {
|
|
73
75
|
initGetOAuth2Authorize,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import initAuthCookies from './authCookies';
|
|
2
|
-
import type { AuthCookiesConfig } from './authCookies';
|
|
1
|
+
import initAuthCookies from './authCookies.js';
|
|
2
|
+
import type { AuthCookiesConfig } from './authCookies.js';
|
|
3
3
|
|
|
4
4
|
describe('authCookies', () => {
|
|
5
5
|
describe('.build()', () => {
|
|
@@ -4,6 +4,7 @@ import { autoService } from 'knifecycle';
|
|
|
4
4
|
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
5
5
|
|
|
6
6
|
export const AUTH_API_PREFIX = '/auth';
|
|
7
|
+
export const DEFAULT_COOKIES_ENV = {};
|
|
7
8
|
|
|
8
9
|
export type AuthHandlersConfig<
|
|
9
10
|
AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,
|
|
@@ -11,16 +12,20 @@ export type AuthHandlersConfig<
|
|
|
11
12
|
ROOT_AUTHENTICATION_DATA: AUTHENTICATION_DATA;
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
export type AuthCookiesEnv = {
|
|
16
|
+
DEV_MODE?: string;
|
|
17
|
+
};
|
|
14
18
|
export type AuthCookiesConfig = {
|
|
15
|
-
ENV?: {
|
|
16
|
-
DEV_MODE?: string;
|
|
17
|
-
};
|
|
18
19
|
COOKIES: {
|
|
19
20
|
domain: string;
|
|
20
21
|
};
|
|
21
22
|
BASE_PATH?: string;
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
export type AuthCookiesDependencies = AuthCookiesConfig & {
|
|
26
|
+
ENV?: AuthCookiesEnv;
|
|
27
|
+
};
|
|
28
|
+
|
|
24
29
|
export type AuthCookiesData = {
|
|
25
30
|
refresh_token: string;
|
|
26
31
|
access_token: string;
|
|
@@ -37,10 +42,10 @@ export type AuthCookiesService = {
|
|
|
37
42
|
export default autoService(initAuthCookies);
|
|
38
43
|
|
|
39
44
|
async function initAuthCookies({
|
|
40
|
-
ENV =
|
|
45
|
+
ENV = DEFAULT_COOKIES_ENV,
|
|
41
46
|
COOKIES,
|
|
42
47
|
BASE_PATH = '',
|
|
43
|
-
}:
|
|
48
|
+
}: AuthCookiesDependencies): Promise<AuthCookiesService> {
|
|
44
49
|
function build(data: Partial<AuthCookiesData> = {}, { session = true } = {}) {
|
|
45
50
|
return [
|
|
46
51
|
cookie.serialize('access_token', data.access_token || '', {
|