@whook/oauth2 26.0.0 → 26.0.3
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/dist/index.d.ts +6 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +421 -2
- package/dist/index.test.js.map +1 -1
- package/dist/libs/authorizationRequests.d.ts +6 -0
- package/dist/libs/authorizationRequests.js +22 -0
- package/dist/libs/authorizationRequests.js.map +1 -0
- package/dist/libs/authorizationRequests.test.d.ts +1 -0
- package/dist/libs/authorizationRequests.test.js +24 -0
- package/dist/libs/authorizationRequests.test.js.map +1 -0
- package/dist/libs/errors.d.ts +31 -1
- package/dist/libs/errors.js +49 -0
- package/dist/libs/errors.js.map +1 -1
- package/dist/libs/redirectURI.d.ts +1 -0
- package/dist/libs/redirectURI.js +16 -0
- package/dist/libs/redirectURI.js.map +1 -1
- package/dist/libs/schemas.d.ts +8 -0
- package/dist/libs/schemas.js +8 -0
- package/dist/libs/schemas.js.map +1 -1
- package/dist/libs/verifier.d.ts +3 -0
- package/dist/libs/verifier.js +14 -0
- package/dist/libs/verifier.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.d.ts +30 -14
- package/dist/routes/getOAuth2Authorize.js +92 -30
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +826 -19
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +10 -3
- package/dist/routes/getOAuth2WellKnownMetadata.js +30 -5
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +20 -18
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
- package/dist/routes/postOAuth2PushedAuthorizationRequest.d.ts +137 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js +187 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.d.ts +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +554 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -0
- package/dist/routes/postOAuth2Token.d.ts +12 -0
- package/dist/routes/postOAuth2Token.js +12 -0
- package/dist/routes/postOAuth2Token.js.map +1 -1
- package/dist/services/authCookies.js +8 -4
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +2 -7
- package/dist/services/oAuth2AuthorizationCodeGranter.js +5 -22
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +12 -141
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationRequests.d.ts +41 -0
- package/dist/services/oAuth2AuthorizationRequests.js +61 -0
- package/dist/services/oAuth2AuthorizationRequests.js.map +1 -0
- package/dist/services/oAuth2AuthorizationRequests.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationRequests.test.js +249 -0
- package/dist/services/oAuth2AuthorizationRequests.test.js.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +10 -12
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2ImplicitGranter.js +3 -14
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -1
- package/dist/services/oAuth2ImplicitGranter.test.js +25 -163
- package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -1
- package/package.json +7 -6
- package/src/index.test.ts +459 -3
- package/src/index.ts +17 -0
- package/src/libs/authorizationRequests.test.ts +40 -0
- package/src/libs/authorizationRequests.ts +42 -0
- package/src/libs/errors.ts +87 -1
- package/src/libs/redirectURI.ts +22 -0
- package/src/libs/schemas.ts +10 -0
- package/src/libs/verifier.ts +18 -0
- package/src/routes/getOAuth2Authorize.test.ts +940 -23
- package/src/routes/getOAuth2Authorize.ts +168 -49
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +22 -20
- package/src/routes/getOAuth2WellKnownMetadata.ts +44 -8
- package/src/routes/postOAuth2PushedAuthorizationRequest.test.ts +681 -0
- package/src/routes/postOAuth2PushedAuthorizationRequest.ts +292 -0
- package/src/routes/postOAuth2Token.ts +12 -0
- package/src/services/authCookies.ts +8 -4
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +12 -169
- package/src/services/oAuth2AuthorizationCodeGranter.ts +8 -31
- package/src/services/oAuth2AuthorizationRequests.test.ts +282 -0
- package/src/services/oAuth2AuthorizationRequests.ts +141 -0
- package/src/services/oAuth2Granters.ts +12 -14
- package/src/services/oAuth2ImplicitGranter.test.ts +29 -190
- package/src/services/oAuth2ImplicitGranter.ts +3 -19
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"name": "@whook/oauth2",
|
|
26
|
-
"version": "26.0.
|
|
26
|
+
"version": "26.0.3",
|
|
27
27
|
"description": "OAuth2 implementation for Whook servers",
|
|
28
28
|
"type": "module",
|
|
29
29
|
"publishConfig": {
|
|
@@ -46,12 +46,13 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/nfroidure/whook",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@whook/authorization": "^26.0.
|
|
50
|
-
"@whook/whook": "^26.0.
|
|
49
|
+
"@whook/authorization": "^26.0.3",
|
|
50
|
+
"@whook/whook": "^26.0.2",
|
|
51
51
|
"camelcase": "^9.0.0",
|
|
52
|
-
"common-services": "^20.
|
|
53
|
-
"cookie": "^
|
|
52
|
+
"common-services": "^20.1.0",
|
|
53
|
+
"cookie": "^2.0.1",
|
|
54
54
|
"knifecycle": "^21.3.0",
|
|
55
|
+
"memory-kv-store": "^10.1.0",
|
|
55
56
|
"type-fest": "^5.6.0",
|
|
56
57
|
"ya-json-schema-types": "^2.0.2",
|
|
57
58
|
"ya-open-api-types": "^2.2.0",
|
|
@@ -135,7 +136,7 @@
|
|
|
135
136
|
"rebuild": "swc ./src -s -d dist -C jsc.target=es2022",
|
|
136
137
|
"test": "node --run jest"
|
|
137
138
|
},
|
|
138
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "e3add4a95e84f83766b3b21514011ded515bc314",
|
|
139
140
|
"funding": {
|
|
140
141
|
"type": "individual",
|
|
141
142
|
"url": "https://github.com/sponsors/nfroidure"
|
package/src/index.test.ts
CHANGED
|
@@ -35,7 +35,9 @@ import {
|
|
|
35
35
|
getOAuth2AuthorizeRedirectURIParameter,
|
|
36
36
|
getOAuth2AuthorizeScopeParameter,
|
|
37
37
|
getOAuth2AuthorizeStateParameter,
|
|
38
|
+
getOAuth2AuthorizeRequestURIParameter,
|
|
38
39
|
getOAuth2AuthorizeScopeSchema,
|
|
40
|
+
getOAuth2AuthorizeRequestURISchema,
|
|
39
41
|
getOAuth2AuthorizeCodeChallengeSchema,
|
|
40
42
|
getOAuth2AuthorizeCodeChallengeParameter,
|
|
41
43
|
getOAuth2AuthorizeCodeChallengeMethodSchema,
|
|
@@ -57,6 +59,10 @@ import {
|
|
|
57
59
|
postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
58
60
|
postOAuth2TokenTokenBodySchema,
|
|
59
61
|
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
62
|
+
postOAuth2PushedAuthorizationRequestBodySchema,
|
|
63
|
+
postOAuth2PushedAuthorizationRequestDefinition,
|
|
64
|
+
postOAuth2PushedAuthorizationRequestRequestURISchema,
|
|
65
|
+
initPostOAuth2PushedAuthorizationRequest,
|
|
60
66
|
type WhookOAuth2Options,
|
|
61
67
|
type WhookOAuth2ReadClientGrantsService,
|
|
62
68
|
type WhookOAuth2PasswordService,
|
|
@@ -68,6 +74,10 @@ import { type Knifecycle } from 'knifecycle';
|
|
|
68
74
|
import { type OpenAPI } from 'ya-open-api-types';
|
|
69
75
|
import { type Logger } from 'common-services';
|
|
70
76
|
import { type WhookAuthenticationService } from '@whook/authorization';
|
|
77
|
+
import {
|
|
78
|
+
type WhookOAuth2AuthorizationRequestsOptions,
|
|
79
|
+
type WhookOAuth2AuthorizationRequestsService,
|
|
80
|
+
} from './services/oAuth2AuthorizationRequests.js';
|
|
71
81
|
|
|
72
82
|
describe('OAuth2 server', () => {
|
|
73
83
|
const BASE_PATH = '/v1';
|
|
@@ -113,6 +123,16 @@ describe('OAuth2 server', () => {
|
|
|
113
123
|
],
|
|
114
124
|
},
|
|
115
125
|
},
|
|
126
|
+
[`${BASE_PATH}${postOAuth2PushedAuthorizationRequestDefinition.path}`]: {
|
|
127
|
+
[postOAuth2PushedAuthorizationRequestDefinition.method]: {
|
|
128
|
+
...postOAuth2PushedAuthorizationRequestDefinition.operation,
|
|
129
|
+
security: [
|
|
130
|
+
{
|
|
131
|
+
basicAuth: ['oauth'],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
116
136
|
},
|
|
117
137
|
components: {
|
|
118
138
|
securitySchemes: {
|
|
@@ -133,6 +153,7 @@ describe('OAuth2 server', () => {
|
|
|
133
153
|
getOAuth2AuthorizeRedirectURIParameter,
|
|
134
154
|
getOAuth2AuthorizeScopeParameter,
|
|
135
155
|
getOAuth2AuthorizeStateParameter,
|
|
156
|
+
getOAuth2AuthorizeRequestURIParameter,
|
|
136
157
|
getOAuth2AuthorizeCodeChallengeParameter,
|
|
137
158
|
getOAuth2AuthorizeCodeChallengeMethodParameter,
|
|
138
159
|
].reduce(
|
|
@@ -144,6 +165,7 @@ describe('OAuth2 server', () => {
|
|
|
144
165
|
),
|
|
145
166
|
schemas: [
|
|
146
167
|
getOAuth2AuthorizeScopeSchema,
|
|
168
|
+
getOAuth2AuthorizeRequestURISchema,
|
|
147
169
|
getOAuth2AuthorizeCodeChallengeSchema,
|
|
148
170
|
getOAuth2AuthorizeCodeChallengeMethodSchema,
|
|
149
171
|
postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
|
|
@@ -152,6 +174,8 @@ describe('OAuth2 server', () => {
|
|
|
152
174
|
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
153
175
|
postOAuth2TokenTokenBodySchema,
|
|
154
176
|
postOAuth2TokenCodeVerifierSchema,
|
|
177
|
+
postOAuth2PushedAuthorizationRequestBodySchema,
|
|
178
|
+
postOAuth2PushedAuthorizationRequestRequestURISchema,
|
|
155
179
|
].reduce(
|
|
156
180
|
(schemasHash, { name, schema }) => ({
|
|
157
181
|
...schemasHash,
|
|
@@ -169,6 +193,10 @@ describe('OAuth2 server', () => {
|
|
|
169
193
|
const authentication = {
|
|
170
194
|
check: jest.fn<WhookAuthenticationService<any>['check']>(),
|
|
171
195
|
};
|
|
196
|
+
const oAuth2AuthorizationRequests = {
|
|
197
|
+
check: jest.fn<WhookOAuth2AuthorizationRequestsService['check']>(),
|
|
198
|
+
create: jest.fn<WhookOAuth2AuthorizationRequestsService['create']>(),
|
|
199
|
+
};
|
|
172
200
|
const readClientGrants = jest.fn<WhookOAuth2ReadClientGrantsService>();
|
|
173
201
|
const oAuth2AccessToken = {
|
|
174
202
|
create: jest.fn<WhookOAuth2AccessTokenService['create']>(),
|
|
@@ -226,6 +254,11 @@ describe('OAuth2 server', () => {
|
|
|
226
254
|
|
|
227
255
|
// OAuth2 Specifics
|
|
228
256
|
$.register(constant('OAUTH2', OAUTH2));
|
|
257
|
+
$.register(
|
|
258
|
+
constant('OAUTH2_PAR', {
|
|
259
|
+
mode: 'enabled',
|
|
260
|
+
} satisfies WhookOAuth2AuthorizationRequestsOptions),
|
|
261
|
+
);
|
|
229
262
|
$.register(
|
|
230
263
|
constant('ERRORS_DESCRIPTORS', {
|
|
231
264
|
...DEFAULT_ERRORS_DESCRIPTORS,
|
|
@@ -235,12 +268,20 @@ describe('OAuth2 server', () => {
|
|
|
235
268
|
);
|
|
236
269
|
$.register(
|
|
237
270
|
alsoInject(
|
|
238
|
-
[
|
|
271
|
+
[
|
|
272
|
+
'getOAuth2Authorize',
|
|
273
|
+
'postOAuth2Acknowledge',
|
|
274
|
+
'postOAuth2Token',
|
|
275
|
+
'postOAuth2PushedAuthorizationRequest',
|
|
276
|
+
],
|
|
239
277
|
initRoutesHandlers,
|
|
240
278
|
),
|
|
241
279
|
);
|
|
242
280
|
$.register(constant('authentication', authentication));
|
|
243
281
|
$.register(constant('readClientGrants', readClientGrants));
|
|
282
|
+
$.register(
|
|
283
|
+
constant('oAuth2AuthorizationRequests', oAuth2AuthorizationRequests),
|
|
284
|
+
);
|
|
244
285
|
$.register(constant('oAuth2AccessToken', oAuth2AccessToken));
|
|
245
286
|
$.register(constant('oAuth2RefreshToken', oAuth2RefreshToken));
|
|
246
287
|
$.register(constant('oAuth2AuthorizationCode', oAuth2AuthorizationCode));
|
|
@@ -255,6 +296,7 @@ describe('OAuth2 server', () => {
|
|
|
255
296
|
initOAuth2PasswordGranter,
|
|
256
297
|
initOAuth2RefreshTokenGranter,
|
|
257
298
|
initOAuth2ImplicitGranter,
|
|
299
|
+
initPostOAuth2PushedAuthorizationRequest,
|
|
258
300
|
].forEach((handlerInitializer) => $.register(handlerInitializer as any));
|
|
259
301
|
|
|
260
302
|
return $;
|
|
@@ -296,6 +338,8 @@ describe('OAuth2 server', () => {
|
|
|
296
338
|
oAuth2Password.check,
|
|
297
339
|
readClientGrants,
|
|
298
340
|
authentication.check,
|
|
341
|
+
oAuth2AuthorizationRequests.check,
|
|
342
|
+
oAuth2AuthorizationRequests.create,
|
|
299
343
|
].forEach((mock) => mock.mockReset());
|
|
300
344
|
});
|
|
301
345
|
|
|
@@ -308,7 +352,9 @@ describe('OAuth2 server', () => {
|
|
|
308
352
|
oAuth2AuthorizationCode.check,
|
|
309
353
|
oAuth2AuthorizationCode.create,
|
|
310
354
|
oAuth2RefreshToken.check,
|
|
311
|
-
|
|
355
|
+
oAuth2AuthorizationRequests.check,
|
|
356
|
+
oAuth2AuthorizationRequests.create,
|
|
357
|
+
].forEach((mock) =>
|
|
312
358
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
313
359
|
);
|
|
314
360
|
authentication.check.mockResolvedValueOnce({
|
|
@@ -483,7 +529,9 @@ describe('OAuth2 server', () => {
|
|
|
483
529
|
oAuth2Password.check,
|
|
484
530
|
oAuth2AccessToken.create,
|
|
485
531
|
oAuth2RefreshToken.create,
|
|
486
|
-
|
|
532
|
+
oAuth2AuthorizationRequests.check,
|
|
533
|
+
oAuth2AuthorizationRequests.create,
|
|
534
|
+
].forEach((mock) =>
|
|
487
535
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
488
536
|
);
|
|
489
537
|
authentication.check.mockResolvedValueOnce({
|
|
@@ -607,6 +655,8 @@ describe('OAuth2 server', () => {
|
|
|
607
655
|
oAuth2AuthorizationCode.check,
|
|
608
656
|
oAuth2AuthorizationCode.create,
|
|
609
657
|
oAuth2Password.check,
|
|
658
|
+
oAuth2AuthorizationRequests.check,
|
|
659
|
+
oAuth2AuthorizationRequests.create,
|
|
610
660
|
].forEach((mock) =>
|
|
611
661
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
612
662
|
);
|
|
@@ -770,6 +820,8 @@ describe('OAuth2 server', () => {
|
|
|
770
820
|
oAuth2Password.check,
|
|
771
821
|
oAuth2AccessToken.create,
|
|
772
822
|
oAuth2RefreshToken.create,
|
|
823
|
+
oAuth2AuthorizationRequests.check,
|
|
824
|
+
oAuth2AuthorizationRequests.create,
|
|
773
825
|
].forEach((mock) =>
|
|
774
826
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
775
827
|
);
|
|
@@ -902,6 +954,8 @@ describe('OAuth2 server', () => {
|
|
|
902
954
|
oAuth2Password.check,
|
|
903
955
|
oAuth2AccessToken.create,
|
|
904
956
|
oAuth2RefreshToken.create,
|
|
957
|
+
oAuth2AuthorizationRequests.check,
|
|
958
|
+
oAuth2AuthorizationRequests.create,
|
|
905
959
|
].forEach((mock) =>
|
|
906
960
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
907
961
|
);
|
|
@@ -1031,6 +1085,8 @@ describe('OAuth2 server', () => {
|
|
|
1031
1085
|
oAuth2AuthorizationCode.check,
|
|
1032
1086
|
oAuth2AuthorizationCode.create,
|
|
1033
1087
|
oAuth2Password.check,
|
|
1088
|
+
oAuth2AuthorizationRequests.check,
|
|
1089
|
+
oAuth2AuthorizationRequests.create,
|
|
1034
1090
|
].forEach((mock) =>
|
|
1035
1091
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1036
1092
|
);
|
|
@@ -1171,6 +1227,8 @@ describe('OAuth2 server', () => {
|
|
|
1171
1227
|
oAuth2Password.check,
|
|
1172
1228
|
oAuth2AccessToken.create,
|
|
1173
1229
|
oAuth2RefreshToken.create,
|
|
1230
|
+
oAuth2AuthorizationRequests.check,
|
|
1231
|
+
oAuth2AuthorizationRequests.create,
|
|
1174
1232
|
].forEach((mock) =>
|
|
1175
1233
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1176
1234
|
);
|
|
@@ -1297,6 +1355,8 @@ describe('OAuth2 server', () => {
|
|
|
1297
1355
|
oAuth2AuthorizationCode.check,
|
|
1298
1356
|
oAuth2AuthorizationCode.create,
|
|
1299
1357
|
oAuth2Password.check,
|
|
1358
|
+
oAuth2AuthorizationRequests.check,
|
|
1359
|
+
oAuth2AuthorizationRequests.create,
|
|
1300
1360
|
].forEach((mock) =>
|
|
1301
1361
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1302
1362
|
);
|
|
@@ -1398,6 +1458,8 @@ describe('OAuth2 server', () => {
|
|
|
1398
1458
|
oAuth2RefreshToken.create,
|
|
1399
1459
|
oAuth2AuthorizationCode.check,
|
|
1400
1460
|
oAuth2Password.check,
|
|
1461
|
+
oAuth2AuthorizationRequests.check,
|
|
1462
|
+
oAuth2AuthorizationRequests.create,
|
|
1401
1463
|
].forEach((mock) =>
|
|
1402
1464
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1403
1465
|
);
|
|
@@ -1547,6 +1609,8 @@ describe('OAuth2 server', () => {
|
|
|
1547
1609
|
oAuth2AccessToken.check,
|
|
1548
1610
|
oAuth2RefreshToken.check,
|
|
1549
1611
|
oAuth2Password.check,
|
|
1612
|
+
oAuth2AuthorizationRequests.check,
|
|
1613
|
+
oAuth2AuthorizationRequests.create,
|
|
1550
1614
|
].forEach((mock) =>
|
|
1551
1615
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1552
1616
|
);
|
|
@@ -1729,6 +1793,8 @@ describe('OAuth2 server', () => {
|
|
|
1729
1793
|
oAuth2AuthorizationCode.check,
|
|
1730
1794
|
oAuth2AuthorizationCode.create,
|
|
1731
1795
|
oAuth2Password.check,
|
|
1796
|
+
oAuth2AuthorizationRequests.check,
|
|
1797
|
+
oAuth2AuthorizationRequests.create,
|
|
1732
1798
|
].forEach((mock) =>
|
|
1733
1799
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1734
1800
|
);
|
|
@@ -1827,6 +1893,8 @@ describe('OAuth2 server', () => {
|
|
|
1827
1893
|
oAuth2AuthorizationCode.check,
|
|
1828
1894
|
oAuth2AuthorizationCode.create,
|
|
1829
1895
|
oAuth2Password.check,
|
|
1896
|
+
oAuth2AuthorizationRequests.check,
|
|
1897
|
+
oAuth2AuthorizationRequests.create,
|
|
1830
1898
|
].forEach((mock) =>
|
|
1831
1899
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
1832
1900
|
);
|
|
@@ -1964,4 +2032,392 @@ describe('OAuth2 server', () => {
|
|
|
1964
2032
|
`);
|
|
1965
2033
|
});
|
|
1966
2034
|
});
|
|
2035
|
+
|
|
2036
|
+
describe('with PAR flow', () => {
|
|
2037
|
+
test('should prepare the authorization redirection', async () => {
|
|
2038
|
+
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
2039
|
+
[
|
|
2040
|
+
oAuth2AccessToken.check,
|
|
2041
|
+
oAuth2AccessToken.create,
|
|
2042
|
+
oAuth2RefreshToken.check,
|
|
2043
|
+
oAuth2RefreshToken.create,
|
|
2044
|
+
oAuth2AuthorizationCode.check,
|
|
2045
|
+
oAuth2AuthorizationCode.create,
|
|
2046
|
+
oAuth2Password.check,
|
|
2047
|
+
oAuth2AuthorizationRequests.check,
|
|
2048
|
+
].forEach((mock) =>
|
|
2049
|
+
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
2050
|
+
);
|
|
2051
|
+
authentication.check.mockResolvedValueOnce({
|
|
2052
|
+
clientId: 'the_client_id',
|
|
2053
|
+
scopes: ['user', 'oauth'],
|
|
2054
|
+
userId: 'auth_user_id',
|
|
2055
|
+
});
|
|
2056
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2057
|
+
allowedGrantTypes: ['implicit'],
|
|
2058
|
+
allowedScopes: ['user', 'oauth'],
|
|
2059
|
+
allowedRedirectURIS: ['http://redirect.example.com/yolo'],
|
|
2060
|
+
isPublicClient: false,
|
|
2061
|
+
authenticationData: {
|
|
2062
|
+
clientId: 'the_client_id',
|
|
2063
|
+
scopes: ['user', 'oauth'],
|
|
2064
|
+
userId: 'a_user_id',
|
|
2065
|
+
},
|
|
2066
|
+
});
|
|
2067
|
+
oAuth2AuthorizationRequests.create.mockResolvedValueOnce({
|
|
2068
|
+
requestURI: 'urn:ietf:params:oauth:request_uri:a_request_uri',
|
|
2069
|
+
expiresIn: 95000,
|
|
2070
|
+
});
|
|
2071
|
+
|
|
2072
|
+
const { status, headers, data } = await axios({
|
|
2073
|
+
method: 'post',
|
|
2074
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2PushedAuthorizationRequestDefinition.path}`,
|
|
2075
|
+
headers: {
|
|
2076
|
+
authorization: `basic ${Buffer.from('ali:open_sesame').toString(
|
|
2077
|
+
'base64',
|
|
2078
|
+
)}`,
|
|
2079
|
+
},
|
|
2080
|
+
data: {
|
|
2081
|
+
response_type: 'token',
|
|
2082
|
+
client_id: 'the_client_id',
|
|
2083
|
+
redirect_uri: 'http://redirect.example.com/yolo',
|
|
2084
|
+
scope: 'user',
|
|
2085
|
+
state: 'xyz',
|
|
2086
|
+
},
|
|
2087
|
+
maxRedirects: 0,
|
|
2088
|
+
validateStatus: () => true,
|
|
2089
|
+
});
|
|
2090
|
+
|
|
2091
|
+
expect({
|
|
2092
|
+
response: {
|
|
2093
|
+
status,
|
|
2094
|
+
headers: {
|
|
2095
|
+
...headers,
|
|
2096
|
+
// Erasing the Date header that may be added by Axios :/
|
|
2097
|
+
date: undefined,
|
|
2098
|
+
etag: undefined,
|
|
2099
|
+
'last-modified': undefined,
|
|
2100
|
+
server: undefined,
|
|
2101
|
+
connection: undefined,
|
|
2102
|
+
'keep-alive': undefined,
|
|
2103
|
+
},
|
|
2104
|
+
data,
|
|
2105
|
+
},
|
|
2106
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
2107
|
+
authenticationCheckCalls: authentication.check.mock.calls,
|
|
2108
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
2109
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
2110
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
2111
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
2112
|
+
oAuth2AuthorizationCodeCheckCalls:
|
|
2113
|
+
oAuth2AuthorizationCode.check.mock.calls,
|
|
2114
|
+
oAuth2AuthorizationCodeCreateCalls:
|
|
2115
|
+
oAuth2AuthorizationCode.create.mock.calls,
|
|
2116
|
+
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
2117
|
+
}).toMatchInlineSnapshot(`
|
|
2118
|
+
{
|
|
2119
|
+
"authenticationCheckCalls": [
|
|
2120
|
+
[
|
|
2121
|
+
"basic",
|
|
2122
|
+
{
|
|
2123
|
+
"hash": "YWxpOm9wZW5fc2VzYW1l",
|
|
2124
|
+
"password": "open_sesame",
|
|
2125
|
+
"username": "ali",
|
|
2126
|
+
},
|
|
2127
|
+
],
|
|
2128
|
+
],
|
|
2129
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
2130
|
+
"oAuth2AccessTokenCreateCalls": [],
|
|
2131
|
+
"oAuth2AuthorizationCodeCheckCalls": [],
|
|
2132
|
+
"oAuth2AuthorizationCodeCreateCalls": [],
|
|
2133
|
+
"oAuth2PasswordCheckCalls": [],
|
|
2134
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
2135
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
2136
|
+
"readClientGrantsCalls": [
|
|
2137
|
+
[
|
|
2138
|
+
"the_client_id",
|
|
2139
|
+
],
|
|
2140
|
+
],
|
|
2141
|
+
"response": {
|
|
2142
|
+
"data": {
|
|
2143
|
+
"expires_in": 95,
|
|
2144
|
+
"request_uri": "urn:ietf:params:oauth:request_uri:a_request_uri",
|
|
2145
|
+
},
|
|
2146
|
+
"headers": {
|
|
2147
|
+
"cache-control": "no-store",
|
|
2148
|
+
"connection": undefined,
|
|
2149
|
+
"content-type": "application/json",
|
|
2150
|
+
"date": undefined,
|
|
2151
|
+
"etag": undefined,
|
|
2152
|
+
"keep-alive": undefined,
|
|
2153
|
+
"last-modified": undefined,
|
|
2154
|
+
"pragma": "no-cache",
|
|
2155
|
+
"server": undefined,
|
|
2156
|
+
"transaction-id": "12",
|
|
2157
|
+
"transfer-encoding": "chunked",
|
|
2158
|
+
"x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
|
|
2159
|
+
},
|
|
2160
|
+
"status": 201,
|
|
2161
|
+
},
|
|
2162
|
+
}
|
|
2163
|
+
`);
|
|
2164
|
+
});
|
|
2165
|
+
|
|
2166
|
+
test('should build the authorization redirection', async () => {
|
|
2167
|
+
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
2168
|
+
[
|
|
2169
|
+
authentication.check,
|
|
2170
|
+
oAuth2AccessToken.check,
|
|
2171
|
+
oAuth2AccessToken.create,
|
|
2172
|
+
oAuth2RefreshToken.check,
|
|
2173
|
+
oAuth2RefreshToken.create,
|
|
2174
|
+
oAuth2AuthorizationCode.check,
|
|
2175
|
+
oAuth2AuthorizationCode.create,
|
|
2176
|
+
oAuth2Password.check,
|
|
2177
|
+
oAuth2AuthorizationRequests.create,
|
|
2178
|
+
].forEach((mock) =>
|
|
2179
|
+
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
2180
|
+
);
|
|
2181
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2182
|
+
allowedGrantTypes: ['implicit'],
|
|
2183
|
+
allowedScopes: ['user', 'oauth'],
|
|
2184
|
+
allowedRedirectURIS: ['http://redirect.example.com/yolo'],
|
|
2185
|
+
isPublicClient: false,
|
|
2186
|
+
authenticationData: {
|
|
2187
|
+
clientId: 'the_client_id',
|
|
2188
|
+
scopes: ['user', 'oauth'],
|
|
2189
|
+
userId: 'a_user_id',
|
|
2190
|
+
},
|
|
2191
|
+
});
|
|
2192
|
+
oAuth2AuthorizationRequests.check.mockResolvedValueOnce({
|
|
2193
|
+
clientId: 'the_client_id',
|
|
2194
|
+
parameters: {
|
|
2195
|
+
response_type: 'token',
|
|
2196
|
+
client_id: 'the_client_id',
|
|
2197
|
+
redirect_uri: 'http://redirect.example.com/yolo',
|
|
2198
|
+
scope: 'user',
|
|
2199
|
+
state: 'xyz',
|
|
2200
|
+
},
|
|
2201
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
2202
|
+
});
|
|
2203
|
+
|
|
2204
|
+
const { status, headers, data } = await axios({
|
|
2205
|
+
method: 'get',
|
|
2206
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`,
|
|
2207
|
+
params: {
|
|
2208
|
+
client_id: 'the_client_id',
|
|
2209
|
+
request_uri: 'urn:ietf:params:oauth:request_uri:a_request_uri',
|
|
2210
|
+
},
|
|
2211
|
+
maxRedirects: 0,
|
|
2212
|
+
validateStatus: () => true,
|
|
2213
|
+
});
|
|
2214
|
+
|
|
2215
|
+
expect({
|
|
2216
|
+
response: {
|
|
2217
|
+
status,
|
|
2218
|
+
headers: {
|
|
2219
|
+
...headers,
|
|
2220
|
+
// Erasing the Date header that may be added by Axios :/
|
|
2221
|
+
date: undefined,
|
|
2222
|
+
etag: undefined,
|
|
2223
|
+
'last-modified': undefined,
|
|
2224
|
+
server: undefined,
|
|
2225
|
+
connection: undefined,
|
|
2226
|
+
'keep-alive': undefined,
|
|
2227
|
+
},
|
|
2228
|
+
data,
|
|
2229
|
+
},
|
|
2230
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
2231
|
+
authenticationCheckCalls: authentication.check.mock.calls,
|
|
2232
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
2233
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
2234
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
2235
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
2236
|
+
oAuth2AuthorizationCodeCheckCalls:
|
|
2237
|
+
oAuth2AuthorizationCode.check.mock.calls,
|
|
2238
|
+
oAuth2AuthorizationCodeCreateCalls:
|
|
2239
|
+
oAuth2AuthorizationCode.create.mock.calls,
|
|
2240
|
+
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
2241
|
+
}).toMatchInlineSnapshot(`
|
|
2242
|
+
{
|
|
2243
|
+
"authenticationCheckCalls": [],
|
|
2244
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
2245
|
+
"oAuth2AccessTokenCreateCalls": [],
|
|
2246
|
+
"oAuth2AuthorizationCodeCheckCalls": [],
|
|
2247
|
+
"oAuth2AuthorizationCodeCreateCalls": [],
|
|
2248
|
+
"oAuth2PasswordCheckCalls": [],
|
|
2249
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
2250
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
2251
|
+
"readClientGrantsCalls": [
|
|
2252
|
+
[
|
|
2253
|
+
"the_client_id",
|
|
2254
|
+
],
|
|
2255
|
+
],
|
|
2256
|
+
"response": {
|
|
2257
|
+
"data": "",
|
|
2258
|
+
"headers": {
|
|
2259
|
+
"connection": undefined,
|
|
2260
|
+
"date": undefined,
|
|
2261
|
+
"etag": undefined,
|
|
2262
|
+
"keep-alive": undefined,
|
|
2263
|
+
"last-modified": undefined,
|
|
2264
|
+
"location": "https://auth.example.com/sign_in?type=token&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&scope=user&client_id=the_client_id&state=xyz",
|
|
2265
|
+
"server": undefined,
|
|
2266
|
+
"transaction-id": "13",
|
|
2267
|
+
"transfer-encoding": "chunked",
|
|
2268
|
+
},
|
|
2269
|
+
"status": 302,
|
|
2270
|
+
},
|
|
2271
|
+
}
|
|
2272
|
+
`);
|
|
2273
|
+
});
|
|
2274
|
+
|
|
2275
|
+
test('should redirect with a token', async () => {
|
|
2276
|
+
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
2277
|
+
[
|
|
2278
|
+
oAuth2AccessToken.check,
|
|
2279
|
+
oAuth2RefreshToken.check,
|
|
2280
|
+
oAuth2RefreshToken.create,
|
|
2281
|
+
oAuth2AuthorizationCode.check,
|
|
2282
|
+
oAuth2AuthorizationCode.create,
|
|
2283
|
+
oAuth2Password.check,
|
|
2284
|
+
oAuth2AuthorizationRequests.check,
|
|
2285
|
+
oAuth2AuthorizationRequests.create,
|
|
2286
|
+
].forEach((mock) =>
|
|
2287
|
+
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
2288
|
+
);
|
|
2289
|
+
authentication.check.mockResolvedValueOnce({
|
|
2290
|
+
clientId: 'the_root_client_id',
|
|
2291
|
+
scopes: ['user', 'oauth'],
|
|
2292
|
+
userId: 'auth_user_id',
|
|
2293
|
+
});
|
|
2294
|
+
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
2295
|
+
token: 'an_access_token',
|
|
2296
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
2297
|
+
});
|
|
2298
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2299
|
+
allowedGrantTypes: ['password'],
|
|
2300
|
+
allowedScopes: [],
|
|
2301
|
+
allowedRedirectURIS: [],
|
|
2302
|
+
isPublicClient: false,
|
|
2303
|
+
canAcknowledge: true,
|
|
2304
|
+
authenticationData: {
|
|
2305
|
+
clientId: 'the_root_client_id',
|
|
2306
|
+
scopes: [],
|
|
2307
|
+
userId: 'a_user_id',
|
|
2308
|
+
},
|
|
2309
|
+
});
|
|
2310
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2311
|
+
allowedGrantTypes: ['implicit'],
|
|
2312
|
+
allowedScopes: ['user', 'oauth'],
|
|
2313
|
+
allowedRedirectURIS: [
|
|
2314
|
+
'http://redirect.example.com/yolo?a_param=a_value',
|
|
2315
|
+
],
|
|
2316
|
+
isPublicClient: true,
|
|
2317
|
+
authenticationData: {
|
|
2318
|
+
clientId: 'the_client_id',
|
|
2319
|
+
scopes: ['user', 'oauth'],
|
|
2320
|
+
userId: 'a_user_id',
|
|
2321
|
+
},
|
|
2322
|
+
});
|
|
2323
|
+
|
|
2324
|
+
const { status, headers, data } = await axios({
|
|
2325
|
+
method: 'post',
|
|
2326
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2AcknowledgeDefinition.path}`,
|
|
2327
|
+
headers: {
|
|
2328
|
+
authorization: 'Bearer yolo',
|
|
2329
|
+
},
|
|
2330
|
+
data: {
|
|
2331
|
+
responseType: 'token',
|
|
2332
|
+
clientId: 'the_client_id',
|
|
2333
|
+
redirectURI: 'http://redirect.example.com/yolo?a_param=a_value',
|
|
2334
|
+
scope: 'user',
|
|
2335
|
+
state: 'xyz',
|
|
2336
|
+
acknowledged: true,
|
|
2337
|
+
},
|
|
2338
|
+
maxRedirects: 0,
|
|
2339
|
+
validateStatus: () => true,
|
|
2340
|
+
});
|
|
2341
|
+
|
|
2342
|
+
expect({
|
|
2343
|
+
response: {
|
|
2344
|
+
status,
|
|
2345
|
+
headers: {
|
|
2346
|
+
...headers,
|
|
2347
|
+
// Erasing the Date header that may be added by Axios :/
|
|
2348
|
+
date: undefined,
|
|
2349
|
+
etag: undefined,
|
|
2350
|
+
'last-modified': undefined,
|
|
2351
|
+
server: undefined,
|
|
2352
|
+
connection: undefined,
|
|
2353
|
+
'keep-alive': undefined,
|
|
2354
|
+
},
|
|
2355
|
+
data,
|
|
2356
|
+
},
|
|
2357
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
2358
|
+
authenticationCheckCalls: authentication.check.mock.calls,
|
|
2359
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
2360
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
2361
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
2362
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
2363
|
+
oAuth2AuthorizationCodeCheckCalls:
|
|
2364
|
+
oAuth2AuthorizationCode.check.mock.calls,
|
|
2365
|
+
oAuth2AuthorizationCodeCreateCalls:
|
|
2366
|
+
oAuth2AuthorizationCode.create.mock.calls,
|
|
2367
|
+
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
2368
|
+
}).toMatchInlineSnapshot(`
|
|
2369
|
+
{
|
|
2370
|
+
"authenticationCheckCalls": [
|
|
2371
|
+
[
|
|
2372
|
+
"bearer",
|
|
2373
|
+
{
|
|
2374
|
+
"hash": "yolo",
|
|
2375
|
+
},
|
|
2376
|
+
],
|
|
2377
|
+
],
|
|
2378
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
2379
|
+
"oAuth2AccessTokenCreateCalls": [
|
|
2380
|
+
[
|
|
2381
|
+
{
|
|
2382
|
+
"clientId": "the_client_id",
|
|
2383
|
+
"scopes": [
|
|
2384
|
+
"user",
|
|
2385
|
+
],
|
|
2386
|
+
"userId": "auth_user_id",
|
|
2387
|
+
},
|
|
2388
|
+
],
|
|
2389
|
+
],
|
|
2390
|
+
"oAuth2AuthorizationCodeCheckCalls": [],
|
|
2391
|
+
"oAuth2AuthorizationCodeCreateCalls": [],
|
|
2392
|
+
"oAuth2PasswordCheckCalls": [],
|
|
2393
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
2394
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
2395
|
+
"readClientGrantsCalls": [
|
|
2396
|
+
[
|
|
2397
|
+
"the_root_client_id",
|
|
2398
|
+
],
|
|
2399
|
+
[
|
|
2400
|
+
"the_client_id",
|
|
2401
|
+
],
|
|
2402
|
+
],
|
|
2403
|
+
"response": {
|
|
2404
|
+
"data": "",
|
|
2405
|
+
"headers": {
|
|
2406
|
+
"connection": undefined,
|
|
2407
|
+
"date": undefined,
|
|
2408
|
+
"etag": undefined,
|
|
2409
|
+
"keep-alive": undefined,
|
|
2410
|
+
"last-modified": undefined,
|
|
2411
|
+
"location": "http://redirect.example.com/yolo?a_param=a_value#client_id=the_client_id&scope=user&state=xyz&access_token=an_access_token&token_type=bearer&expires_in=86400",
|
|
2412
|
+
"server": undefined,
|
|
2413
|
+
"transaction-id": "14",
|
|
2414
|
+
"transfer-encoding": "chunked",
|
|
2415
|
+
"x-authenticated": "{"clientId":"the_root_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
|
|
2416
|
+
},
|
|
2417
|
+
"status": 201,
|
|
2418
|
+
},
|
|
2419
|
+
}
|
|
2420
|
+
`);
|
|
2421
|
+
});
|
|
2422
|
+
});
|
|
1967
2423
|
});
|