@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/dist/index.test.js
CHANGED
|
@@ -6,7 +6,7 @@ import { alsoInject, constant, initializer } from 'knifecycle';
|
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { YError } from 'yerror';
|
|
8
8
|
import { BEARER as BEARER_MECHANISM, BASIC as BASIC_MECHANISM, } from 'http-auth-utils';
|
|
9
|
-
import { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeScopeSchema, getOAuth2AuthorizeCodeChallengeSchema, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodSchema, getOAuth2AuthorizeCodeChallengeMethodParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenCodeVerifierSchema, postOAuth2TokenDefinition, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2AuthorizationCodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2ImplicitGranter, postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, postOAuth2TokenPasswordTokenRequestBodySchema, postOAuth2TokenClientCredentialsTokenRequestBodySchema, postOAuth2TokenTokenBodySchema, postOAuth2TokenRefreshTokenRequestBodySchema, } from './index.js';
|
|
9
|
+
import { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeRequestURIParameter, getOAuth2AuthorizeScopeSchema, getOAuth2AuthorizeRequestURISchema, getOAuth2AuthorizeCodeChallengeSchema, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodSchema, getOAuth2AuthorizeCodeChallengeMethodParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenCodeVerifierSchema, postOAuth2TokenDefinition, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2AuthorizationCodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2ImplicitGranter, postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, postOAuth2TokenPasswordTokenRequestBodySchema, postOAuth2TokenClientCredentialsTokenRequestBodySchema, postOAuth2TokenTokenBodySchema, postOAuth2TokenRefreshTokenRequestBodySchema, postOAuth2PushedAuthorizationRequestBodySchema, postOAuth2PushedAuthorizationRequestDefinition, postOAuth2PushedAuthorizationRequestRequestURISchema, initPostOAuth2PushedAuthorizationRequest, } from './index.js';
|
|
10
10
|
describe('OAuth2 server', () => {
|
|
11
11
|
const BASE_PATH = '/v1';
|
|
12
12
|
const PORT = 4444;
|
|
@@ -49,6 +49,16 @@ describe('OAuth2 server', () => {
|
|
|
49
49
|
],
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
+
[`${BASE_PATH}${postOAuth2PushedAuthorizationRequestDefinition.path}`]: {
|
|
53
|
+
[postOAuth2PushedAuthorizationRequestDefinition.method]: {
|
|
54
|
+
...postOAuth2PushedAuthorizationRequestDefinition.operation,
|
|
55
|
+
security: [
|
|
56
|
+
{
|
|
57
|
+
basicAuth: ['oauth'],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
52
62
|
},
|
|
53
63
|
components: {
|
|
54
64
|
securitySchemes: {
|
|
@@ -69,6 +79,7 @@ describe('OAuth2 server', () => {
|
|
|
69
79
|
getOAuth2AuthorizeRedirectURIParameter,
|
|
70
80
|
getOAuth2AuthorizeScopeParameter,
|
|
71
81
|
getOAuth2AuthorizeStateParameter,
|
|
82
|
+
getOAuth2AuthorizeRequestURIParameter,
|
|
72
83
|
getOAuth2AuthorizeCodeChallengeParameter,
|
|
73
84
|
getOAuth2AuthorizeCodeChallengeMethodParameter,
|
|
74
85
|
].reduce((parametersHash, { name, parameter }) => ({
|
|
@@ -77,6 +88,7 @@ describe('OAuth2 server', () => {
|
|
|
77
88
|
}), {}),
|
|
78
89
|
schemas: [
|
|
79
90
|
getOAuth2AuthorizeScopeSchema,
|
|
91
|
+
getOAuth2AuthorizeRequestURISchema,
|
|
80
92
|
getOAuth2AuthorizeCodeChallengeSchema,
|
|
81
93
|
getOAuth2AuthorizeCodeChallengeMethodSchema,
|
|
82
94
|
postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
|
|
@@ -85,6 +97,8 @@ describe('OAuth2 server', () => {
|
|
|
85
97
|
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
86
98
|
postOAuth2TokenTokenBodySchema,
|
|
87
99
|
postOAuth2TokenCodeVerifierSchema,
|
|
100
|
+
postOAuth2PushedAuthorizationRequestBodySchema,
|
|
101
|
+
postOAuth2PushedAuthorizationRequestRequestURISchema,
|
|
88
102
|
].reduce((schemasHash, { name, schema }) => ({
|
|
89
103
|
...schemasHash,
|
|
90
104
|
[name]: schema,
|
|
@@ -99,6 +113,10 @@ describe('OAuth2 server', () => {
|
|
|
99
113
|
const authentication = {
|
|
100
114
|
check: jest.fn(),
|
|
101
115
|
};
|
|
116
|
+
const oAuth2AuthorizationRequests = {
|
|
117
|
+
check: jest.fn(),
|
|
118
|
+
create: jest.fn(),
|
|
119
|
+
};
|
|
102
120
|
const readClientGrants = jest.fn();
|
|
103
121
|
const oAuth2AccessToken = {
|
|
104
122
|
create: jest.fn(),
|
|
@@ -143,14 +161,23 @@ describe('OAuth2 server', () => {
|
|
|
143
161
|
$.register(constant('ROUTES_WRAPPERS_NAMES', ROUTES_WRAPPERS_NAMES));
|
|
144
162
|
// OAuth2 Specifics
|
|
145
163
|
$.register(constant('OAUTH2', OAUTH2));
|
|
164
|
+
$.register(constant('OAUTH2_PAR', {
|
|
165
|
+
mode: 'enabled',
|
|
166
|
+
}));
|
|
146
167
|
$.register(constant('ERRORS_DESCRIPTORS', {
|
|
147
168
|
...DEFAULT_ERRORS_DESCRIPTORS,
|
|
148
169
|
...AUTHORIZATION_ERRORS_DESCRIPTORS,
|
|
149
170
|
...OAUTH2_ERRORS_DESCRIPTORS,
|
|
150
171
|
}));
|
|
151
|
-
$.register(alsoInject([
|
|
172
|
+
$.register(alsoInject([
|
|
173
|
+
'getOAuth2Authorize',
|
|
174
|
+
'postOAuth2Acknowledge',
|
|
175
|
+
'postOAuth2Token',
|
|
176
|
+
'postOAuth2PushedAuthorizationRequest',
|
|
177
|
+
], initRoutesHandlers));
|
|
152
178
|
$.register(constant('authentication', authentication));
|
|
153
179
|
$.register(constant('readClientGrants', readClientGrants));
|
|
180
|
+
$.register(constant('oAuth2AuthorizationRequests', oAuth2AuthorizationRequests));
|
|
154
181
|
$.register(constant('oAuth2AccessToken', oAuth2AccessToken));
|
|
155
182
|
$.register(constant('oAuth2RefreshToken', oAuth2RefreshToken));
|
|
156
183
|
$.register(constant('oAuth2AuthorizationCode', oAuth2AuthorizationCode));
|
|
@@ -165,6 +192,7 @@ describe('OAuth2 server', () => {
|
|
|
165
192
|
initOAuth2PasswordGranter,
|
|
166
193
|
initOAuth2RefreshTokenGranter,
|
|
167
194
|
initOAuth2ImplicitGranter,
|
|
195
|
+
initPostOAuth2PushedAuthorizationRequest,
|
|
168
196
|
].forEach((handlerInitializer) => $.register(handlerInitializer));
|
|
169
197
|
return $;
|
|
170
198
|
}
|
|
@@ -199,6 +227,8 @@ describe('OAuth2 server', () => {
|
|
|
199
227
|
oAuth2Password.check,
|
|
200
228
|
readClientGrants,
|
|
201
229
|
authentication.check,
|
|
230
|
+
oAuth2AuthorizationRequests.check,
|
|
231
|
+
oAuth2AuthorizationRequests.create,
|
|
202
232
|
].forEach((mock) => mock.mockReset());
|
|
203
233
|
});
|
|
204
234
|
describe('with the password flow', () => {
|
|
@@ -210,6 +240,8 @@ describe('OAuth2 server', () => {
|
|
|
210
240
|
oAuth2AuthorizationCode.check,
|
|
211
241
|
oAuth2AuthorizationCode.create,
|
|
212
242
|
oAuth2RefreshToken.check,
|
|
243
|
+
oAuth2AuthorizationRequests.check,
|
|
244
|
+
oAuth2AuthorizationRequests.create,
|
|
213
245
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
214
246
|
authentication.check.mockResolvedValueOnce({
|
|
215
247
|
clientId: 'the_client_id',
|
|
@@ -376,6 +408,8 @@ describe('OAuth2 server', () => {
|
|
|
376
408
|
oAuth2Password.check,
|
|
377
409
|
oAuth2AccessToken.create,
|
|
378
410
|
oAuth2RefreshToken.create,
|
|
411
|
+
oAuth2AuthorizationRequests.check,
|
|
412
|
+
oAuth2AuthorizationRequests.create,
|
|
379
413
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
380
414
|
authentication.check.mockResolvedValueOnce({
|
|
381
415
|
clientId: 'the_client_id',
|
|
@@ -491,6 +525,8 @@ describe('OAuth2 server', () => {
|
|
|
491
525
|
oAuth2AuthorizationCode.check,
|
|
492
526
|
oAuth2AuthorizationCode.create,
|
|
493
527
|
oAuth2Password.check,
|
|
528
|
+
oAuth2AuthorizationRequests.check,
|
|
529
|
+
oAuth2AuthorizationRequests.create,
|
|
494
530
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
495
531
|
authentication.check.mockResolvedValueOnce({
|
|
496
532
|
clientId: 'the_client_id',
|
|
@@ -645,6 +681,8 @@ describe('OAuth2 server', () => {
|
|
|
645
681
|
oAuth2Password.check,
|
|
646
682
|
oAuth2AccessToken.create,
|
|
647
683
|
oAuth2RefreshToken.create,
|
|
684
|
+
oAuth2AuthorizationRequests.check,
|
|
685
|
+
oAuth2AuthorizationRequests.create,
|
|
648
686
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
649
687
|
authentication.check.mockResolvedValueOnce({
|
|
650
688
|
clientId: 'the_client_id',
|
|
@@ -768,6 +806,8 @@ describe('OAuth2 server', () => {
|
|
|
768
806
|
oAuth2Password.check,
|
|
769
807
|
oAuth2AccessToken.create,
|
|
770
808
|
oAuth2RefreshToken.create,
|
|
809
|
+
oAuth2AuthorizationRequests.check,
|
|
810
|
+
oAuth2AuthorizationRequests.create,
|
|
771
811
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
772
812
|
authentication.check.mockResolvedValueOnce({
|
|
773
813
|
clientId: 'another_client_id',
|
|
@@ -888,6 +928,8 @@ describe('OAuth2 server', () => {
|
|
|
888
928
|
oAuth2AuthorizationCode.check,
|
|
889
929
|
oAuth2AuthorizationCode.create,
|
|
890
930
|
oAuth2Password.check,
|
|
931
|
+
oAuth2AuthorizationRequests.check,
|
|
932
|
+
oAuth2AuthorizationRequests.create,
|
|
891
933
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
892
934
|
authentication.check.mockResolvedValueOnce({
|
|
893
935
|
clientId: 'the_client_id',
|
|
@@ -1020,6 +1062,8 @@ describe('OAuth2 server', () => {
|
|
|
1020
1062
|
oAuth2Password.check,
|
|
1021
1063
|
oAuth2AccessToken.create,
|
|
1022
1064
|
oAuth2RefreshToken.create,
|
|
1065
|
+
oAuth2AuthorizationRequests.check,
|
|
1066
|
+
oAuth2AuthorizationRequests.create,
|
|
1023
1067
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1024
1068
|
authentication.check.mockResolvedValueOnce({
|
|
1025
1069
|
clientId: 'the_client_id',
|
|
@@ -1137,6 +1181,8 @@ describe('OAuth2 server', () => {
|
|
|
1137
1181
|
oAuth2AuthorizationCode.check,
|
|
1138
1182
|
oAuth2AuthorizationCode.create,
|
|
1139
1183
|
oAuth2Password.check,
|
|
1184
|
+
oAuth2AuthorizationRequests.check,
|
|
1185
|
+
oAuth2AuthorizationRequests.create,
|
|
1140
1186
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1141
1187
|
readClientGrants.mockResolvedValueOnce({
|
|
1142
1188
|
allowedGrantTypes: ['authorization_code', 'refresh_token'],
|
|
@@ -1230,6 +1276,8 @@ describe('OAuth2 server', () => {
|
|
|
1230
1276
|
oAuth2RefreshToken.create,
|
|
1231
1277
|
oAuth2AuthorizationCode.check,
|
|
1232
1278
|
oAuth2Password.check,
|
|
1279
|
+
oAuth2AuthorizationRequests.check,
|
|
1280
|
+
oAuth2AuthorizationRequests.create,
|
|
1233
1281
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1234
1282
|
authentication.check.mockResolvedValueOnce({
|
|
1235
1283
|
clientId: 'the_root_client_id',
|
|
@@ -1372,6 +1420,8 @@ describe('OAuth2 server', () => {
|
|
|
1372
1420
|
oAuth2AccessToken.check,
|
|
1373
1421
|
oAuth2RefreshToken.check,
|
|
1374
1422
|
oAuth2Password.check,
|
|
1423
|
+
oAuth2AuthorizationRequests.check,
|
|
1424
|
+
oAuth2AuthorizationRequests.create,
|
|
1375
1425
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1376
1426
|
authentication.check.mockResolvedValueOnce({
|
|
1377
1427
|
clientId: 'the_client_id',
|
|
@@ -1545,6 +1595,8 @@ describe('OAuth2 server', () => {
|
|
|
1545
1595
|
oAuth2AuthorizationCode.check,
|
|
1546
1596
|
oAuth2AuthorizationCode.create,
|
|
1547
1597
|
oAuth2Password.check,
|
|
1598
|
+
oAuth2AuthorizationRequests.check,
|
|
1599
|
+
oAuth2AuthorizationRequests.create,
|
|
1548
1600
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1549
1601
|
readClientGrants.mockResolvedValueOnce({
|
|
1550
1602
|
allowedGrantTypes: ['implicit'],
|
|
@@ -1636,6 +1688,8 @@ describe('OAuth2 server', () => {
|
|
|
1636
1688
|
oAuth2AuthorizationCode.check,
|
|
1637
1689
|
oAuth2AuthorizationCode.create,
|
|
1638
1690
|
oAuth2Password.check,
|
|
1691
|
+
oAuth2AuthorizationRequests.check,
|
|
1692
|
+
oAuth2AuthorizationRequests.create,
|
|
1639
1693
|
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1640
1694
|
authentication.check.mockResolvedValueOnce({
|
|
1641
1695
|
clientId: 'the_root_client_id',
|
|
@@ -1767,5 +1821,370 @@ describe('OAuth2 server', () => {
|
|
|
1767
1821
|
`);
|
|
1768
1822
|
});
|
|
1769
1823
|
});
|
|
1824
|
+
describe('with PAR flow', () => {
|
|
1825
|
+
test('should prepare the authorization redirection', async () => {
|
|
1826
|
+
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
1827
|
+
[
|
|
1828
|
+
oAuth2AccessToken.check,
|
|
1829
|
+
oAuth2AccessToken.create,
|
|
1830
|
+
oAuth2RefreshToken.check,
|
|
1831
|
+
oAuth2RefreshToken.create,
|
|
1832
|
+
oAuth2AuthorizationCode.check,
|
|
1833
|
+
oAuth2AuthorizationCode.create,
|
|
1834
|
+
oAuth2Password.check,
|
|
1835
|
+
oAuth2AuthorizationRequests.check,
|
|
1836
|
+
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1837
|
+
authentication.check.mockResolvedValueOnce({
|
|
1838
|
+
clientId: 'the_client_id',
|
|
1839
|
+
scopes: ['user', 'oauth'],
|
|
1840
|
+
userId: 'auth_user_id',
|
|
1841
|
+
});
|
|
1842
|
+
readClientGrants.mockResolvedValueOnce({
|
|
1843
|
+
allowedGrantTypes: ['implicit'],
|
|
1844
|
+
allowedScopes: ['user', 'oauth'],
|
|
1845
|
+
allowedRedirectURIS: ['http://redirect.example.com/yolo'],
|
|
1846
|
+
isPublicClient: false,
|
|
1847
|
+
authenticationData: {
|
|
1848
|
+
clientId: 'the_client_id',
|
|
1849
|
+
scopes: ['user', 'oauth'],
|
|
1850
|
+
userId: 'a_user_id',
|
|
1851
|
+
},
|
|
1852
|
+
});
|
|
1853
|
+
oAuth2AuthorizationRequests.create.mockResolvedValueOnce({
|
|
1854
|
+
requestURI: 'urn:ietf:params:oauth:request_uri:a_request_uri',
|
|
1855
|
+
expiresIn: 95000,
|
|
1856
|
+
});
|
|
1857
|
+
const { status, headers, data } = await axios({
|
|
1858
|
+
method: 'post',
|
|
1859
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2PushedAuthorizationRequestDefinition.path}`,
|
|
1860
|
+
headers: {
|
|
1861
|
+
authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
|
|
1862
|
+
},
|
|
1863
|
+
data: {
|
|
1864
|
+
response_type: 'token',
|
|
1865
|
+
client_id: 'the_client_id',
|
|
1866
|
+
redirect_uri: 'http://redirect.example.com/yolo',
|
|
1867
|
+
scope: 'user',
|
|
1868
|
+
state: 'xyz',
|
|
1869
|
+
},
|
|
1870
|
+
maxRedirects: 0,
|
|
1871
|
+
validateStatus: () => true,
|
|
1872
|
+
});
|
|
1873
|
+
expect({
|
|
1874
|
+
response: {
|
|
1875
|
+
status,
|
|
1876
|
+
headers: {
|
|
1877
|
+
...headers,
|
|
1878
|
+
// Erasing the Date header that may be added by Axios :/
|
|
1879
|
+
date: undefined,
|
|
1880
|
+
etag: undefined,
|
|
1881
|
+
'last-modified': undefined,
|
|
1882
|
+
server: undefined,
|
|
1883
|
+
connection: undefined,
|
|
1884
|
+
'keep-alive': undefined,
|
|
1885
|
+
},
|
|
1886
|
+
data,
|
|
1887
|
+
},
|
|
1888
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
1889
|
+
authenticationCheckCalls: authentication.check.mock.calls,
|
|
1890
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
1891
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
1892
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
1893
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
1894
|
+
oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
|
|
1895
|
+
oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
|
|
1896
|
+
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
1897
|
+
}).toMatchInlineSnapshot(`
|
|
1898
|
+
{
|
|
1899
|
+
"authenticationCheckCalls": [
|
|
1900
|
+
[
|
|
1901
|
+
"basic",
|
|
1902
|
+
{
|
|
1903
|
+
"hash": "YWxpOm9wZW5fc2VzYW1l",
|
|
1904
|
+
"password": "open_sesame",
|
|
1905
|
+
"username": "ali",
|
|
1906
|
+
},
|
|
1907
|
+
],
|
|
1908
|
+
],
|
|
1909
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
1910
|
+
"oAuth2AccessTokenCreateCalls": [],
|
|
1911
|
+
"oAuth2AuthorizationCodeCheckCalls": [],
|
|
1912
|
+
"oAuth2AuthorizationCodeCreateCalls": [],
|
|
1913
|
+
"oAuth2PasswordCheckCalls": [],
|
|
1914
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
1915
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
1916
|
+
"readClientGrantsCalls": [
|
|
1917
|
+
[
|
|
1918
|
+
"the_client_id",
|
|
1919
|
+
],
|
|
1920
|
+
],
|
|
1921
|
+
"response": {
|
|
1922
|
+
"data": {
|
|
1923
|
+
"expires_in": 95,
|
|
1924
|
+
"request_uri": "urn:ietf:params:oauth:request_uri:a_request_uri",
|
|
1925
|
+
},
|
|
1926
|
+
"headers": {
|
|
1927
|
+
"cache-control": "no-store",
|
|
1928
|
+
"connection": undefined,
|
|
1929
|
+
"content-type": "application/json",
|
|
1930
|
+
"date": undefined,
|
|
1931
|
+
"etag": undefined,
|
|
1932
|
+
"keep-alive": undefined,
|
|
1933
|
+
"last-modified": undefined,
|
|
1934
|
+
"pragma": "no-cache",
|
|
1935
|
+
"server": undefined,
|
|
1936
|
+
"transaction-id": "12",
|
|
1937
|
+
"transfer-encoding": "chunked",
|
|
1938
|
+
"x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
|
|
1939
|
+
},
|
|
1940
|
+
"status": 201,
|
|
1941
|
+
},
|
|
1942
|
+
}
|
|
1943
|
+
`);
|
|
1944
|
+
});
|
|
1945
|
+
test('should build the authorization redirection', async () => {
|
|
1946
|
+
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
1947
|
+
[
|
|
1948
|
+
authentication.check,
|
|
1949
|
+
oAuth2AccessToken.check,
|
|
1950
|
+
oAuth2AccessToken.create,
|
|
1951
|
+
oAuth2RefreshToken.check,
|
|
1952
|
+
oAuth2RefreshToken.create,
|
|
1953
|
+
oAuth2AuthorizationCode.check,
|
|
1954
|
+
oAuth2AuthorizationCode.create,
|
|
1955
|
+
oAuth2Password.check,
|
|
1956
|
+
oAuth2AuthorizationRequests.create,
|
|
1957
|
+
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
1958
|
+
readClientGrants.mockResolvedValueOnce({
|
|
1959
|
+
allowedGrantTypes: ['implicit'],
|
|
1960
|
+
allowedScopes: ['user', 'oauth'],
|
|
1961
|
+
allowedRedirectURIS: ['http://redirect.example.com/yolo'],
|
|
1962
|
+
isPublicClient: false,
|
|
1963
|
+
authenticationData: {
|
|
1964
|
+
clientId: 'the_client_id',
|
|
1965
|
+
scopes: ['user', 'oauth'],
|
|
1966
|
+
userId: 'a_user_id',
|
|
1967
|
+
},
|
|
1968
|
+
});
|
|
1969
|
+
oAuth2AuthorizationRequests.check.mockResolvedValueOnce({
|
|
1970
|
+
clientId: 'the_client_id',
|
|
1971
|
+
parameters: {
|
|
1972
|
+
response_type: 'token',
|
|
1973
|
+
client_id: 'the_client_id',
|
|
1974
|
+
redirect_uri: 'http://redirect.example.com/yolo',
|
|
1975
|
+
scope: 'user',
|
|
1976
|
+
state: 'xyz',
|
|
1977
|
+
},
|
|
1978
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
1979
|
+
});
|
|
1980
|
+
const { status, headers, data } = await axios({
|
|
1981
|
+
method: 'get',
|
|
1982
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`,
|
|
1983
|
+
params: {
|
|
1984
|
+
client_id: 'the_client_id',
|
|
1985
|
+
request_uri: 'urn:ietf:params:oauth:request_uri:a_request_uri',
|
|
1986
|
+
},
|
|
1987
|
+
maxRedirects: 0,
|
|
1988
|
+
validateStatus: () => true,
|
|
1989
|
+
});
|
|
1990
|
+
expect({
|
|
1991
|
+
response: {
|
|
1992
|
+
status,
|
|
1993
|
+
headers: {
|
|
1994
|
+
...headers,
|
|
1995
|
+
// Erasing the Date header that may be added by Axios :/
|
|
1996
|
+
date: undefined,
|
|
1997
|
+
etag: undefined,
|
|
1998
|
+
'last-modified': undefined,
|
|
1999
|
+
server: undefined,
|
|
2000
|
+
connection: undefined,
|
|
2001
|
+
'keep-alive': undefined,
|
|
2002
|
+
},
|
|
2003
|
+
data,
|
|
2004
|
+
},
|
|
2005
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
2006
|
+
authenticationCheckCalls: authentication.check.mock.calls,
|
|
2007
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
2008
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
2009
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
2010
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
2011
|
+
oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
|
|
2012
|
+
oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
|
|
2013
|
+
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
2014
|
+
}).toMatchInlineSnapshot(`
|
|
2015
|
+
{
|
|
2016
|
+
"authenticationCheckCalls": [],
|
|
2017
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
2018
|
+
"oAuth2AccessTokenCreateCalls": [],
|
|
2019
|
+
"oAuth2AuthorizationCodeCheckCalls": [],
|
|
2020
|
+
"oAuth2AuthorizationCodeCreateCalls": [],
|
|
2021
|
+
"oAuth2PasswordCheckCalls": [],
|
|
2022
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
2023
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
2024
|
+
"readClientGrantsCalls": [
|
|
2025
|
+
[
|
|
2026
|
+
"the_client_id",
|
|
2027
|
+
],
|
|
2028
|
+
],
|
|
2029
|
+
"response": {
|
|
2030
|
+
"data": "",
|
|
2031
|
+
"headers": {
|
|
2032
|
+
"connection": undefined,
|
|
2033
|
+
"date": undefined,
|
|
2034
|
+
"etag": undefined,
|
|
2035
|
+
"keep-alive": undefined,
|
|
2036
|
+
"last-modified": undefined,
|
|
2037
|
+
"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",
|
|
2038
|
+
"server": undefined,
|
|
2039
|
+
"transaction-id": "13",
|
|
2040
|
+
"transfer-encoding": "chunked",
|
|
2041
|
+
},
|
|
2042
|
+
"status": 302,
|
|
2043
|
+
},
|
|
2044
|
+
}
|
|
2045
|
+
`);
|
|
2046
|
+
});
|
|
2047
|
+
test('should redirect with a token', async () => {
|
|
2048
|
+
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
2049
|
+
[
|
|
2050
|
+
oAuth2AccessToken.check,
|
|
2051
|
+
oAuth2RefreshToken.check,
|
|
2052
|
+
oAuth2RefreshToken.create,
|
|
2053
|
+
oAuth2AuthorizationCode.check,
|
|
2054
|
+
oAuth2AuthorizationCode.create,
|
|
2055
|
+
oAuth2Password.check,
|
|
2056
|
+
oAuth2AuthorizationRequests.check,
|
|
2057
|
+
oAuth2AuthorizationRequests.create,
|
|
2058
|
+
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
2059
|
+
authentication.check.mockResolvedValueOnce({
|
|
2060
|
+
clientId: 'the_root_client_id',
|
|
2061
|
+
scopes: ['user', 'oauth'],
|
|
2062
|
+
userId: 'auth_user_id',
|
|
2063
|
+
});
|
|
2064
|
+
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
2065
|
+
token: 'an_access_token',
|
|
2066
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
2067
|
+
});
|
|
2068
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2069
|
+
allowedGrantTypes: ['password'],
|
|
2070
|
+
allowedScopes: [],
|
|
2071
|
+
allowedRedirectURIS: [],
|
|
2072
|
+
isPublicClient: false,
|
|
2073
|
+
canAcknowledge: true,
|
|
2074
|
+
authenticationData: {
|
|
2075
|
+
clientId: 'the_root_client_id',
|
|
2076
|
+
scopes: [],
|
|
2077
|
+
userId: 'a_user_id',
|
|
2078
|
+
},
|
|
2079
|
+
});
|
|
2080
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2081
|
+
allowedGrantTypes: ['implicit'],
|
|
2082
|
+
allowedScopes: ['user', 'oauth'],
|
|
2083
|
+
allowedRedirectURIS: [
|
|
2084
|
+
'http://redirect.example.com/yolo?a_param=a_value',
|
|
2085
|
+
],
|
|
2086
|
+
isPublicClient: true,
|
|
2087
|
+
authenticationData: {
|
|
2088
|
+
clientId: 'the_client_id',
|
|
2089
|
+
scopes: ['user', 'oauth'],
|
|
2090
|
+
userId: 'a_user_id',
|
|
2091
|
+
},
|
|
2092
|
+
});
|
|
2093
|
+
const { status, headers, data } = await axios({
|
|
2094
|
+
method: 'post',
|
|
2095
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2AcknowledgeDefinition.path}`,
|
|
2096
|
+
headers: {
|
|
2097
|
+
authorization: 'Bearer yolo',
|
|
2098
|
+
},
|
|
2099
|
+
data: {
|
|
2100
|
+
responseType: 'token',
|
|
2101
|
+
clientId: 'the_client_id',
|
|
2102
|
+
redirectURI: 'http://redirect.example.com/yolo?a_param=a_value',
|
|
2103
|
+
scope: 'user',
|
|
2104
|
+
state: 'xyz',
|
|
2105
|
+
acknowledged: true,
|
|
2106
|
+
},
|
|
2107
|
+
maxRedirects: 0,
|
|
2108
|
+
validateStatus: () => true,
|
|
2109
|
+
});
|
|
2110
|
+
expect({
|
|
2111
|
+
response: {
|
|
2112
|
+
status,
|
|
2113
|
+
headers: {
|
|
2114
|
+
...headers,
|
|
2115
|
+
// Erasing the Date header that may be added by Axios :/
|
|
2116
|
+
date: undefined,
|
|
2117
|
+
etag: undefined,
|
|
2118
|
+
'last-modified': undefined,
|
|
2119
|
+
server: undefined,
|
|
2120
|
+
connection: undefined,
|
|
2121
|
+
'keep-alive': undefined,
|
|
2122
|
+
},
|
|
2123
|
+
data,
|
|
2124
|
+
},
|
|
2125
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
2126
|
+
authenticationCheckCalls: authentication.check.mock.calls,
|
|
2127
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
2128
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
2129
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
2130
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
2131
|
+
oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
|
|
2132
|
+
oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
|
|
2133
|
+
oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
|
|
2134
|
+
}).toMatchInlineSnapshot(`
|
|
2135
|
+
{
|
|
2136
|
+
"authenticationCheckCalls": [
|
|
2137
|
+
[
|
|
2138
|
+
"bearer",
|
|
2139
|
+
{
|
|
2140
|
+
"hash": "yolo",
|
|
2141
|
+
},
|
|
2142
|
+
],
|
|
2143
|
+
],
|
|
2144
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
2145
|
+
"oAuth2AccessTokenCreateCalls": [
|
|
2146
|
+
[
|
|
2147
|
+
{
|
|
2148
|
+
"clientId": "the_client_id",
|
|
2149
|
+
"scopes": [
|
|
2150
|
+
"user",
|
|
2151
|
+
],
|
|
2152
|
+
"userId": "auth_user_id",
|
|
2153
|
+
},
|
|
2154
|
+
],
|
|
2155
|
+
],
|
|
2156
|
+
"oAuth2AuthorizationCodeCheckCalls": [],
|
|
2157
|
+
"oAuth2AuthorizationCodeCreateCalls": [],
|
|
2158
|
+
"oAuth2PasswordCheckCalls": [],
|
|
2159
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
2160
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
2161
|
+
"readClientGrantsCalls": [
|
|
2162
|
+
[
|
|
2163
|
+
"the_root_client_id",
|
|
2164
|
+
],
|
|
2165
|
+
[
|
|
2166
|
+
"the_client_id",
|
|
2167
|
+
],
|
|
2168
|
+
],
|
|
2169
|
+
"response": {
|
|
2170
|
+
"data": "",
|
|
2171
|
+
"headers": {
|
|
2172
|
+
"connection": undefined,
|
|
2173
|
+
"date": undefined,
|
|
2174
|
+
"etag": undefined,
|
|
2175
|
+
"keep-alive": undefined,
|
|
2176
|
+
"last-modified": undefined,
|
|
2177
|
+
"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",
|
|
2178
|
+
"server": undefined,
|
|
2179
|
+
"transaction-id": "14",
|
|
2180
|
+
"transfer-encoding": "chunked",
|
|
2181
|
+
"x-authenticated": "{"clientId":"the_root_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
|
|
2182
|
+
},
|
|
2183
|
+
"status": 201,
|
|
2184
|
+
},
|
|
2185
|
+
}
|
|
2186
|
+
`);
|
|
2187
|
+
});
|
|
2188
|
+
});
|
|
1770
2189
|
});
|
|
1771
2190
|
//# sourceMappingURL=index.test.js.map
|