@whook/oauth2 26.0.0 → 26.0.2
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
|
@@ -39,102 +39,26 @@ describe('OAuth2ImplicitGranter', () => {
|
|
|
39
39
|
log,
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
readClientGrants.mockResolvedValue({
|
|
43
|
-
allowedRedirectURIS: ['https://www.example.com'],
|
|
44
|
-
allowedGrantTypes: ['implicit', 'authorization_code'],
|
|
45
|
-
allowedScopes: ['user', 'admin'],
|
|
46
|
-
authenticationData: {
|
|
47
|
-
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
48
|
-
userId: 'abbacaca-abba-caca-abba-cacaabbab0b0',
|
|
49
|
-
scopes: [],
|
|
50
|
-
},
|
|
51
|
-
isPublicClient: true,
|
|
52
|
-
});
|
|
53
42
|
oAuth2AccessToken.create.mockRejectedValueOnce(
|
|
54
43
|
new YError('E_NOT_SUPPOSED_TO_BE_HERE'),
|
|
55
44
|
);
|
|
56
45
|
|
|
57
46
|
const authorizerAuthenticateResult =
|
|
58
|
-
await oAuth2AccessTokenGranter.authorize?.(
|
|
59
|
-
{
|
|
60
|
-
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
61
|
-
demandedRedirectURI: 'https://www.example.com',
|
|
62
|
-
demandedScopes: ['user', 'root'],
|
|
63
|
-
},
|
|
64
|
-
{},
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
expect({
|
|
68
|
-
authorizerAuthenticateResult,
|
|
69
|
-
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.create.mock.calls,
|
|
70
|
-
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
71
|
-
logCalls: log.mock.calls,
|
|
72
|
-
timeCalls: time.mock.calls,
|
|
73
|
-
}).toMatchInlineSnapshot(`
|
|
74
|
-
{
|
|
75
|
-
"authorizerAuthenticateResult": {
|
|
76
|
-
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
77
|
-
"redirectURI": "https://www.example.com",
|
|
78
|
-
"scopes": [
|
|
79
|
-
"user",
|
|
80
|
-
],
|
|
81
|
-
"userId": "abbacaca-abba-caca-abba-cacaabbab0b0",
|
|
82
|
-
},
|
|
83
|
-
"logCalls": [
|
|
84
|
-
[
|
|
85
|
-
"warning",
|
|
86
|
-
"⚠️ - Using the token flow is deprecated and not recommended.",
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
"debug",
|
|
90
|
-
"👫 - OAuth2ImplicitGranter Service Initialized!",
|
|
91
|
-
],
|
|
92
|
-
],
|
|
93
|
-
"oAuth2AccessTokenCheckCalls": [],
|
|
94
|
-
"readClientGrantsCalls": [
|
|
95
|
-
[
|
|
96
|
-
"abbacaca-abba-caca-abba-cacaabbacaca",
|
|
97
|
-
],
|
|
98
|
-
],
|
|
99
|
-
"timeCalls": [],
|
|
100
|
-
}
|
|
101
|
-
`);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('should work with a valid request and filter scopes', async () => {
|
|
105
|
-
const oAuth2AccessTokenGranter = await initOAuth2ImplicitGranter({
|
|
106
|
-
OAUTH2,
|
|
107
|
-
readClientGrants,
|
|
108
|
-
oAuth2AccessToken,
|
|
109
|
-
time,
|
|
110
|
-
log,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
readClientGrants.mockResolvedValue({
|
|
114
|
-
allowedRedirectURIS: ['https://www.example.com'],
|
|
115
|
-
allowedGrantTypes: ['implicit', 'authorization_code'],
|
|
116
|
-
allowedScopes: ['user', 'admin'],
|
|
117
|
-
authenticationData: {
|
|
47
|
+
await oAuth2AccessTokenGranter.authorize?.({
|
|
118
48
|
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const authorizerAuthenticateResult =
|
|
130
|
-
await oAuth2AccessTokenGranter.authorize?.(
|
|
131
|
-
{
|
|
132
|
-
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
133
|
-
demandedRedirectURI: 'https://www.example.com',
|
|
134
|
-
demandedScopes: ['user', 'admin', 'oauth2', 'a_scope'],
|
|
49
|
+
clientGrants: {
|
|
50
|
+
allowedRedirectURIS: ['https://www.example.com'],
|
|
51
|
+
allowedGrantTypes: ['implicit', 'authorization_code'],
|
|
52
|
+
allowedScopes: ['user', 'admin'],
|
|
53
|
+
authenticationData: {
|
|
54
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
55
|
+
userId: 'abbacaca-abba-caca-abba-cacaabbab0b0',
|
|
56
|
+
scopes: [],
|
|
57
|
+
},
|
|
58
|
+
isPublicClient: true,
|
|
135
59
|
},
|
|
136
|
-
|
|
137
|
-
);
|
|
60
|
+
demandedScopes: ['user'],
|
|
61
|
+
});
|
|
138
62
|
|
|
139
63
|
expect({
|
|
140
64
|
authorizerAuthenticateResult,
|
|
@@ -145,13 +69,9 @@ describe('OAuth2ImplicitGranter', () => {
|
|
|
145
69
|
}).toMatchInlineSnapshot(`
|
|
146
70
|
{
|
|
147
71
|
"authorizerAuthenticateResult": {
|
|
148
|
-
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
149
|
-
"redirectURI": "https://www.example.com",
|
|
150
72
|
"scopes": [
|
|
151
73
|
"user",
|
|
152
|
-
"admin",
|
|
153
74
|
],
|
|
154
|
-
"userId": "abbacaca-abba-caca-abba-cacaabbab0b0",
|
|
155
75
|
},
|
|
156
76
|
"logCalls": [
|
|
157
77
|
[
|
|
@@ -164,11 +84,7 @@ describe('OAuth2ImplicitGranter', () => {
|
|
|
164
84
|
],
|
|
165
85
|
],
|
|
166
86
|
"oAuth2AccessTokenCheckCalls": [],
|
|
167
|
-
"readClientGrantsCalls": [
|
|
168
|
-
[
|
|
169
|
-
"abbacaca-abba-caca-abba-cacaabbacaca",
|
|
170
|
-
],
|
|
171
|
-
],
|
|
87
|
+
"readClientGrantsCalls": [],
|
|
172
88
|
"timeCalls": [],
|
|
173
89
|
}
|
|
174
90
|
`);
|
|
@@ -183,100 +99,27 @@ describe('OAuth2ImplicitGranter', () => {
|
|
|
183
99
|
log,
|
|
184
100
|
});
|
|
185
101
|
|
|
186
|
-
readClientGrants.mockResolvedValue({
|
|
187
|
-
allowedRedirectURIS: ['https://www.example.com'],
|
|
188
|
-
allowedGrantTypes: ['authorization_code'],
|
|
189
|
-
allowedScopes: ['user', 'admin'],
|
|
190
|
-
authenticationData: {
|
|
191
|
-
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
192
|
-
userId: 'abbacaca-abba-caca-abba-cacaabbab0b0',
|
|
193
|
-
scopes: [],
|
|
194
|
-
},
|
|
195
|
-
isPublicClient: true,
|
|
196
|
-
});
|
|
197
102
|
oAuth2AccessToken.create.mockRejectedValueOnce(
|
|
198
103
|
new YError('E_NOT_SUPPOSED_TO_BE_HERE'),
|
|
199
104
|
);
|
|
200
105
|
time.mockReturnValueOnce(Date.parse('2026-07-22T10:00:00Z'));
|
|
201
106
|
|
|
202
107
|
try {
|
|
203
|
-
await oAuth2AccessTokenGranter.authorize?.(
|
|
204
|
-
{
|
|
205
|
-
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
206
|
-
demandedRedirectURI: 'https://www.example.com',
|
|
207
|
-
demandedScopes: ['user'],
|
|
208
|
-
},
|
|
209
|
-
{},
|
|
210
|
-
);
|
|
211
|
-
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
212
|
-
} catch (err) {
|
|
213
|
-
expect({
|
|
214
|
-
err,
|
|
215
|
-
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.create.mock.calls,
|
|
216
|
-
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
217
|
-
logCalls: log.mock.calls,
|
|
218
|
-
timeCalls: time.mock.calls,
|
|
219
|
-
}).toMatchInlineSnapshot(`
|
|
220
|
-
{
|
|
221
|
-
"err": [YError: E_OAUTH2_GRANT_TYPE_NOT_ALLOWED (["implicit",["authorization_code"]]): E_OAUTH2_GRANT_TYPE_NOT_ALLOWED],
|
|
222
|
-
"logCalls": [
|
|
223
|
-
[
|
|
224
|
-
"warning",
|
|
225
|
-
"⚠️ - Using the token flow is deprecated and not recommended.",
|
|
226
|
-
],
|
|
227
|
-
[
|
|
228
|
-
"debug",
|
|
229
|
-
"👫 - OAuth2ImplicitGranter Service Initialized!",
|
|
230
|
-
],
|
|
231
|
-
],
|
|
232
|
-
"oAuth2AccessTokenCheckCalls": [],
|
|
233
|
-
"readClientGrantsCalls": [
|
|
234
|
-
[
|
|
235
|
-
"abbacaca-abba-caca-abba-cacaabbacaca",
|
|
236
|
-
],
|
|
237
|
-
],
|
|
238
|
-
"timeCalls": [],
|
|
239
|
-
}
|
|
240
|
-
`);
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test('should fail with a client with a bad scope for the client', async () => {
|
|
245
|
-
const oAuth2AccessTokenGranter = await initOAuth2ImplicitGranter({
|
|
246
|
-
OAUTH2: {
|
|
247
|
-
...OAUTH2,
|
|
248
|
-
strictScopesChecks: true,
|
|
249
|
-
},
|
|
250
|
-
readClientGrants,
|
|
251
|
-
oAuth2AccessToken,
|
|
252
|
-
log,
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
readClientGrants.mockResolvedValue({
|
|
256
|
-
allowedRedirectURIS: ['https://www.example.com'],
|
|
257
|
-
allowedGrantTypes: ['implicit'],
|
|
258
|
-
allowedScopes: ['user'],
|
|
259
|
-
authenticationData: {
|
|
108
|
+
await oAuth2AccessTokenGranter.authorize?.({
|
|
260
109
|
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
await oAuth2AccessTokenGranter.authorize?.(
|
|
273
|
-
{
|
|
274
|
-
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
275
|
-
demandedRedirectURI: 'https://www.example.com',
|
|
276
|
-
demandedScopes: ['user', 'admin'],
|
|
110
|
+
clientGrants: {
|
|
111
|
+
allowedRedirectURIS: ['https://www.example.com'],
|
|
112
|
+
allowedGrantTypes: ['authorization_code'],
|
|
113
|
+
allowedScopes: ['user', 'admin'],
|
|
114
|
+
authenticationData: {
|
|
115
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
116
|
+
userId: 'abbacaca-abba-caca-abba-cacaabbab0b0',
|
|
117
|
+
scopes: [],
|
|
118
|
+
},
|
|
119
|
+
isPublicClient: true,
|
|
277
120
|
},
|
|
278
|
-
|
|
279
|
-
);
|
|
121
|
+
demandedScopes: ['user'],
|
|
122
|
+
});
|
|
280
123
|
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
281
124
|
} catch (err) {
|
|
282
125
|
expect({
|
|
@@ -287,7 +130,7 @@ describe('OAuth2ImplicitGranter', () => {
|
|
|
287
130
|
timeCalls: time.mock.calls,
|
|
288
131
|
}).toMatchInlineSnapshot(`
|
|
289
132
|
{
|
|
290
|
-
"err": [YError:
|
|
133
|
+
"err": [YError: E_OAUTH2_GRANT_TYPE_NOT_ALLOWED (["implicit",["authorization_code"]]): E_OAUTH2_GRANT_TYPE_NOT_ALLOWED],
|
|
291
134
|
"logCalls": [
|
|
292
135
|
[
|
|
293
136
|
"warning",
|
|
@@ -299,11 +142,7 @@ describe('OAuth2ImplicitGranter', () => {
|
|
|
299
142
|
],
|
|
300
143
|
],
|
|
301
144
|
"oAuth2AccessTokenCheckCalls": [],
|
|
302
|
-
"readClientGrantsCalls": [
|
|
303
|
-
[
|
|
304
|
-
"abbacaca-abba-caca-abba-cacaabbacaca",
|
|
305
|
-
],
|
|
306
|
-
],
|
|
145
|
+
"readClientGrantsCalls": [],
|
|
307
146
|
"timeCalls": [],
|
|
308
147
|
}
|
|
309
148
|
`);
|
|
@@ -70,27 +70,11 @@ async function initOAuth2ImplicitGranter({
|
|
|
70
70
|
|
|
71
71
|
const authorizeWithToken: NonNullable<
|
|
72
72
|
WhookOAuth2ImplicitGranterService['authorize']
|
|
73
|
-
> = async ({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
checkGrantType(grants.allowedGrantTypes, IMPLICIT_GRANT_TYPE);
|
|
77
|
-
if (demandedRedirectURI) {
|
|
78
|
-
checkRedirectURI(grants.allowedRedirectURIS, demandedRedirectURI);
|
|
79
|
-
} else {
|
|
80
|
-
demandedRedirectURI = grants.allowedRedirectURIS[0];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const filteredScopes = filterScopes(
|
|
84
|
-
demandedScopes,
|
|
85
|
-
grants.allowedScopes,
|
|
86
|
-
!!OAUTH2.strictScopesChecks,
|
|
87
|
-
);
|
|
73
|
+
> = async ({ clientGrants, demandedScopes }) => {
|
|
74
|
+
checkGrantType(clientGrants.allowedGrantTypes, IMPLICIT_GRANT_TYPE);
|
|
88
75
|
|
|
89
76
|
return {
|
|
90
|
-
|
|
91
|
-
clientId,
|
|
92
|
-
redirectURI: demandedRedirectURI,
|
|
93
|
-
scopes: filteredScopes,
|
|
77
|
+
scopes: demandedScopes,
|
|
94
78
|
};
|
|
95
79
|
};
|
|
96
80
|
|