@whook/oauth2 25.2.1 → 26.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +147 -98
  2. package/dist/index.d.ts +30 -11
  3. package/dist/index.js +15 -8
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.test.js +1258 -399
  6. package/dist/index.test.js.map +1 -1
  7. package/dist/libs/clients.d.ts +2 -0
  8. package/dist/libs/clients.js +13 -0
  9. package/dist/libs/clients.js.map +1 -0
  10. package/dist/libs/errors.d.ts +113 -0
  11. package/dist/libs/errors.js +178 -0
  12. package/dist/libs/errors.js.map +1 -0
  13. package/dist/libs/grants.d.ts +2 -0
  14. package/dist/libs/grants.js +10 -0
  15. package/dist/libs/grants.js.map +1 -0
  16. package/dist/libs/redirectURI.d.ts +7 -0
  17. package/dist/libs/redirectURI.js +78 -0
  18. package/dist/libs/redirectURI.js.map +1 -0
  19. package/dist/libs/schemas.d.ts +23 -0
  20. package/dist/libs/schemas.js +25 -0
  21. package/dist/libs/schemas.js.map +1 -0
  22. package/dist/libs/scopes.d.ts +16 -0
  23. package/dist/libs/scopes.js +37 -0
  24. package/dist/libs/scopes.js.map +1 -1
  25. package/dist/libs/utils.d.ts +2 -0
  26. package/dist/libs/utils.js +17 -0
  27. package/dist/libs/utils.js.map +1 -0
  28. package/dist/libs/verifier.d.ts +7 -0
  29. package/dist/libs/verifier.js +37 -0
  30. package/dist/libs/verifier.js.map +1 -0
  31. package/dist/libs/verifier.test.js +21 -0
  32. package/dist/libs/verifier.test.js.map +1 -0
  33. package/dist/routes/getOAuth2Authorize.d.ts +13 -50
  34. package/dist/routes/getOAuth2Authorize.js +60 -86
  35. package/dist/routes/getOAuth2Authorize.js.map +1 -1
  36. package/dist/routes/getOAuth2Authorize.test.js +147 -68
  37. package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
  38. package/dist/routes/getOAuth2WellKnownMetadata.d.ts +8 -8
  39. package/dist/routes/getOAuth2WellKnownMetadata.js +15 -8
  40. package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
  41. package/dist/routes/getOAuth2WellKnownMetadata.test.js +37 -37
  42. package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
  43. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +3 -6
  44. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +3 -6
  45. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
  46. package/dist/routes/postAuthLogin.d.ts +14 -9
  47. package/dist/routes/postAuthLogin.js +10 -5
  48. package/dist/routes/postAuthLogin.js.map +1 -1
  49. package/dist/routes/postAuthLogin.test.js +79 -55
  50. package/dist/routes/postAuthLogin.test.js.map +1 -1
  51. package/dist/routes/postAuthLogout.d.ts +5 -2
  52. package/dist/routes/postAuthLogout.js +12 -7
  53. package/dist/routes/postAuthLogout.js.map +1 -1
  54. package/dist/routes/postAuthLogout.test.js +35 -17
  55. package/dist/routes/postAuthLogout.test.js.map +1 -1
  56. package/dist/routes/postAuthRefresh.d.ts +14 -9
  57. package/dist/routes/postAuthRefresh.js +10 -6
  58. package/dist/routes/postAuthRefresh.js.map +1 -1
  59. package/dist/routes/postAuthRefresh.test.js +90 -59
  60. package/dist/routes/postAuthRefresh.test.js.map +1 -1
  61. package/dist/routes/postOAuth2Acknowledge.d.ts +11 -10
  62. package/dist/routes/postOAuth2Acknowledge.js +43 -37
  63. package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
  64. package/dist/routes/postOAuth2Acknowledge.test.js +135 -70
  65. package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
  66. package/dist/routes/postOAuth2Revoke.d.ts +99 -0
  67. package/dist/routes/postOAuth2Revoke.js +102 -0
  68. package/dist/routes/postOAuth2Revoke.js.map +1 -0
  69. package/dist/routes/postOAuth2Revoke.test.d.ts +1 -0
  70. package/dist/routes/postOAuth2Revoke.test.js +161 -0
  71. package/dist/routes/postOAuth2Revoke.test.js.map +1 -0
  72. package/dist/routes/postOAuth2Token.d.ts +35 -108
  73. package/dist/routes/postOAuth2Token.js +53 -114
  74. package/dist/routes/postOAuth2Token.js.map +1 -1
  75. package/dist/routes/postOAuth2Token.test.js +493 -61
  76. package/dist/routes/postOAuth2Token.test.js.map +1 -1
  77. package/dist/services/authCookies.d.ts +9 -13
  78. package/dist/services/authCookies.js +1 -1
  79. package/dist/services/authCookies.js.map +1 -1
  80. package/dist/services/authCookies.test.js.map +1 -1
  81. package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +129 -0
  82. package/dist/services/oAuth2AuthorizationCodeGranter.js +221 -0
  83. package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
  84. package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
  85. package/dist/services/oAuth2AuthorizationCodeGranter.test.js +474 -0
  86. package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -0
  87. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +28 -12
  88. package/dist/services/oAuth2ClientCredentialsGranter.js +39 -21
  89. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  90. package/dist/services/oAuth2ClientCredentialsGranter.test.d.ts +1 -0
  91. package/dist/services/oAuth2ClientCredentialsGranter.test.js +265 -0
  92. package/dist/services/oAuth2ClientCredentialsGranter.test.js.map +1 -0
  93. package/dist/services/oAuth2Granters.d.ts +81 -86
  94. package/dist/services/oAuth2Granters.js +2 -67
  95. package/dist/services/oAuth2Granters.js.map +1 -1
  96. package/dist/services/oAuth2ImplicitGranter.d.ts +38 -0
  97. package/dist/services/oAuth2ImplicitGranter.js +72 -0
  98. package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
  99. package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
  100. package/dist/services/oAuth2ImplicitGranter.test.js +727 -0
  101. package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -0
  102. package/dist/services/oAuth2PasswordGranter.d.ts +43 -10
  103. package/dist/services/oAuth2PasswordGranter.js +53 -18
  104. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  105. package/dist/services/oAuth2PasswordGranter.test.d.ts +1 -0
  106. package/dist/services/oAuth2PasswordGranter.test.js +455 -0
  107. package/dist/services/oAuth2PasswordGranter.test.js.map +1 -0
  108. package/dist/services/oAuth2RefreshTokenGranter.d.ts +42 -9
  109. package/dist/services/oAuth2RefreshTokenGranter.js +60 -21
  110. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  111. package/dist/services/oAuth2RefreshTokenGranter.test.d.ts +1 -0
  112. package/dist/services/oAuth2RefreshTokenGranter.test.js +403 -0
  113. package/dist/services/oAuth2RefreshTokenGranter.test.js.map +1 -0
  114. package/package.json +11 -11
  115. package/src/index.test.ts +1314 -404
  116. package/src/index.ts +46 -53
  117. package/src/libs/clients.ts +22 -0
  118. package/src/libs/errors.ts +325 -0
  119. package/src/libs/grants.ts +15 -0
  120. package/src/libs/redirectURI.ts +120 -0
  121. package/src/libs/schemas.ts +27 -0
  122. package/src/libs/scopes.ts +49 -0
  123. package/src/libs/utils.ts +24 -0
  124. package/src/libs/verifier.test.ts +37 -0
  125. package/src/libs/verifier.ts +57 -0
  126. package/src/routes/getOAuth2Authorize.test.ts +179 -96
  127. package/src/routes/getOAuth2Authorize.ts +97 -124
  128. package/src/routes/getOAuth2WellKnownMetadata.test.ts +57 -60
  129. package/src/routes/getOAuth2WellKnownMetadata.ts +21 -10
  130. package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +4 -6
  131. package/src/routes/postAuthLogin.test.ts +86 -57
  132. package/src/routes/postAuthLogin.ts +24 -14
  133. package/src/routes/postAuthLogout.test.ts +42 -18
  134. package/src/routes/postAuthLogout.ts +22 -8
  135. package/src/routes/postAuthRefresh.test.ts +98 -61
  136. package/src/routes/postAuthRefresh.ts +25 -13
  137. package/src/routes/postOAuth2Acknowledge.test.ts +167 -108
  138. package/src/routes/postOAuth2Acknowledge.ts +90 -64
  139. package/src/routes/postOAuth2Revoke.test.ts +179 -0
  140. package/src/routes/postOAuth2Revoke.ts +156 -0
  141. package/src/routes/postOAuth2Token.test.ts +570 -108
  142. package/src/routes/postOAuth2Token.ts +92 -136
  143. package/src/services/authCookies.test.ts +5 -5
  144. package/src/services/authCookies.ts +16 -18
  145. package/src/services/oAuth2AuthorizationCodeGranter.test.ts +564 -0
  146. package/src/services/oAuth2AuthorizationCodeGranter.ts +388 -0
  147. package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
  148. package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
  149. package/src/services/oAuth2Granters.ts +101 -195
  150. package/src/services/oAuth2ImplicitGranter.test.ts +811 -0
  151. package/src/services/oAuth2ImplicitGranter.ts +163 -0
  152. package/src/services/oAuth2PasswordGranter.test.ts +493 -0
  153. package/src/services/oAuth2PasswordGranter.ts +116 -40
  154. package/src/services/oAuth2RefreshTokenGranter.test.ts +441 -0
  155. package/src/services/oAuth2RefreshTokenGranter.ts +118 -51
  156. package/src/types.d.ts +1 -0
  157. package/dist/services/oAuth2CodeGranter.d.ts +0 -41
  158. package/dist/services/oAuth2CodeGranter.js +0 -105
  159. package/dist/services/oAuth2CodeGranter.js.map +0 -1
  160. package/dist/services/oAuth2CodeGranter.test.js +0 -123
  161. package/dist/services/oAuth2CodeGranter.test.js.map +0 -1
  162. package/dist/services/oAuth2TokenGranter.d.ts +0 -22
  163. package/dist/services/oAuth2TokenGranter.js +0 -64
  164. package/dist/services/oAuth2TokenGranter.js.map +0 -1
  165. package/src/__snapshots__/index.test.ts.snap +0 -401
  166. package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -37
  167. package/src/routes/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -61
  168. package/src/routes/__snapshots__/postOAuth2Token.test.ts.snap +0 -52
  169. package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +0 -52
  170. package/src/services/oAuth2CodeGranter.test.ts +0 -176
  171. package/src/services/oAuth2CodeGranter.ts +0 -210
  172. package/src/services/oAuth2TokenGranter.ts +0 -119
  173. /package/dist/{services/oAuth2CodeGranter.test.d.ts → libs/verifier.test.d.ts} +0 -0
package/src/index.test.ts CHANGED
@@ -35,6 +35,7 @@ import {
35
35
  getOAuth2AuthorizeRedirectURIParameter,
36
36
  getOAuth2AuthorizeScopeParameter,
37
37
  getOAuth2AuthorizeStateParameter,
38
+ getOAuth2AuthorizeScopeSchema,
38
39
  getOAuth2AuthorizeCodeChallengeSchema,
39
40
  getOAuth2AuthorizeCodeChallengeParameter,
40
41
  getOAuth2AuthorizeCodeChallengeMethodSchema,
@@ -45,23 +46,23 @@ import {
45
46
  postOAuth2TokenCodeVerifierSchema,
46
47
  postOAuth2TokenDefinition,
47
48
  OAUTH2_ERRORS_DESCRIPTORS,
48
- initOAuth2CodeGranter,
49
+ initOAuth2AuthorizationCodeGranter,
49
50
  initOAuth2PasswordGranter,
50
51
  initOAuth2RefreshTokenGranter,
51
52
  initOAuth2Granters,
52
53
  initOAuth2ClientCredentialsGranter,
53
- initOAuth2TokenGranter,
54
+ initOAuth2ImplicitGranter,
54
55
  postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
55
56
  postOAuth2TokenPasswordTokenRequestBodySchema,
56
57
  postOAuth2TokenClientCredentialsTokenRequestBodySchema,
57
58
  postOAuth2TokenTokenBodySchema,
58
59
  postOAuth2TokenRefreshTokenRequestBodySchema,
59
- type OAuth2Options,
60
- type CheckApplicationService,
61
- type OAuth2PasswordService,
62
- type OAuth2CodeService,
63
- type OAuth2RefreshTokenService,
64
- type OAuth2AccessTokenService,
60
+ type WhookOAuth2Options,
61
+ type WhookOAuth2ReadClientGrantsService,
62
+ type WhookOAuth2PasswordService,
63
+ type WhookOAuth2AuthorizationCodeService,
64
+ type WhookOAuth2RefreshTokenService,
65
+ type WhookOAuth2AccessTokenService,
65
66
  } from './index.js';
66
67
  import { type Knifecycle } from 'knifecycle';
67
68
  import { type OpenAPI } from 'ya-open-api-types';
@@ -142,13 +143,14 @@ describe('OAuth2 server', () => {
142
143
  {},
143
144
  ),
144
145
  schemas: [
146
+ getOAuth2AuthorizeScopeSchema,
147
+ getOAuth2AuthorizeCodeChallengeSchema,
148
+ getOAuth2AuthorizeCodeChallengeMethodSchema,
145
149
  postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
146
150
  postOAuth2TokenPasswordTokenRequestBodySchema,
147
151
  postOAuth2TokenClientCredentialsTokenRequestBodySchema,
148
152
  postOAuth2TokenRefreshTokenRequestBodySchema,
149
153
  postOAuth2TokenTokenBodySchema,
150
- getOAuth2AuthorizeCodeChallengeSchema,
151
- getOAuth2AuthorizeCodeChallengeMethodSchema,
152
154
  postOAuth2TokenCodeVerifierSchema,
153
155
  ].reduce(
154
156
  (schemasHash, { name, schema }) => ({
@@ -159,27 +161,29 @@ describe('OAuth2 server', () => {
159
161
  ),
160
162
  },
161
163
  };
162
- const OAUTH2: OAuth2Options = {
164
+ const OAUTH2: WhookOAuth2Options = {
163
165
  authenticateURL: 'https://auth.example.com/sign_in',
166
+ allowedScopes: ['user', 'oauth'],
167
+ rootClientId: 'the_root_client_id',
164
168
  };
165
169
  const authentication = {
166
170
  check: jest.fn<WhookAuthenticationService<any>['check']>(),
167
171
  };
168
- const checkApplication = jest.fn<CheckApplicationService>();
172
+ const readClientGrants = jest.fn<WhookOAuth2ReadClientGrantsService>();
169
173
  const oAuth2AccessToken = {
170
- create: jest.fn<OAuth2AccessTokenService['create']>(),
171
- check: jest.fn<OAuth2AccessTokenService['check']>(),
174
+ create: jest.fn<WhookOAuth2AccessTokenService['create']>(),
175
+ check: jest.fn<WhookOAuth2AccessTokenService['check']>(),
172
176
  };
173
177
  const oAuth2RefreshToken = {
174
- create: jest.fn<OAuth2RefreshTokenService['create']>(),
175
- check: jest.fn<OAuth2RefreshTokenService['check']>(),
178
+ create: jest.fn<WhookOAuth2RefreshTokenService['create']>(),
179
+ check: jest.fn<WhookOAuth2RefreshTokenService['check']>(),
176
180
  };
177
- const oAuth2Code = {
178
- create: jest.fn<OAuth2CodeService['create']>(),
179
- check: jest.fn<OAuth2CodeService['check']>(),
181
+ const oAuth2AuthorizationCode = {
182
+ create: jest.fn<WhookOAuth2AuthorizationCodeService['create']>(),
183
+ check: jest.fn<WhookOAuth2AuthorizationCodeService['check']>(),
180
184
  };
181
185
  const oAuth2Password = {
182
- check: jest.fn<OAuth2PasswordService['check']>(),
186
+ check: jest.fn<WhookOAuth2PasswordService['check']>(),
183
187
  };
184
188
 
185
189
  let $instance: Knifecycle;
@@ -236,10 +240,10 @@ describe('OAuth2 server', () => {
236
240
  ),
237
241
  );
238
242
  $.register(constant('authentication', authentication));
239
- $.register(constant('checkApplication', checkApplication));
243
+ $.register(constant('readClientGrants', readClientGrants));
240
244
  $.register(constant('oAuth2AccessToken', oAuth2AccessToken));
241
245
  $.register(constant('oAuth2RefreshToken', oAuth2RefreshToken));
242
- $.register(constant('oAuth2Code', oAuth2Code));
246
+ $.register(constant('oAuth2AuthorizationCode', oAuth2AuthorizationCode));
243
247
  $.register(constant('oAuth2Password', oAuth2Password));
244
248
  [
245
249
  initGetOAuth2Authorize,
@@ -247,10 +251,10 @@ describe('OAuth2 server', () => {
247
251
  initPostOAuth2Token,
248
252
  initOAuth2Granters,
249
253
  initOAuth2ClientCredentialsGranter,
250
- initOAuth2CodeGranter,
254
+ initOAuth2AuthorizationCodeGranter,
251
255
  initOAuth2PasswordGranter,
252
256
  initOAuth2RefreshTokenGranter,
253
- initOAuth2TokenGranter,
257
+ initOAuth2ImplicitGranter,
254
258
  ].forEach((handlerInitializer) => $.register(handlerInitializer as any));
255
259
 
256
260
  return $;
@@ -287,10 +291,10 @@ describe('OAuth2 server', () => {
287
291
  oAuth2AccessToken.check,
288
292
  oAuth2RefreshToken.create,
289
293
  oAuth2RefreshToken.check,
290
- oAuth2Code.check,
291
- oAuth2Code.create,
294
+ oAuth2AuthorizationCode.check,
295
+ oAuth2AuthorizationCode.create,
292
296
  oAuth2Password.check,
293
- checkApplication,
297
+ readClientGrants,
294
298
  authentication.check,
295
299
  ].forEach((mock) => mock.mockReset());
296
300
  });
@@ -301,27 +305,32 @@ describe('OAuth2 server', () => {
301
305
  [
302
306
  oAuth2AccessToken.check,
303
307
  oAuth2RefreshToken.check,
304
- oAuth2Code.check,
305
- oAuth2Code.create,
308
+ oAuth2AuthorizationCode.check,
309
+ oAuth2AuthorizationCode.create,
306
310
  oAuth2RefreshToken.check,
307
311
  ].forEach((mock: any) =>
308
312
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
309
313
  );
310
314
  authentication.check.mockResolvedValueOnce({
311
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
312
- scope: 'user,oauth',
313
- userId: '2',
315
+ clientId: 'the_client_id',
316
+ scopes: ['user', 'oauth'],
317
+ userId: 'auth_user_id',
314
318
  });
315
- checkApplication.mockResolvedValueOnce({
316
- type: 'code',
317
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
318
- scope: 'user,oauth',
319
- redirectURI: 'http://redirect.example.com/yolo',
319
+ readClientGrants.mockResolvedValueOnce({
320
+ allowedGrantTypes: ['authorization_code', 'password'],
321
+ allowedScopes: ['user', 'oauth'],
322
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
323
+ isPublicClient: false,
324
+ authenticationData: {
325
+ clientId: 'the_client_id',
326
+ scopes: ['user', 'oauth'],
327
+ userId: 'a_user_id',
328
+ },
320
329
  });
321
330
  oAuth2Password.check.mockResolvedValueOnce({
322
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
323
- scope: 'user,auth',
324
- userId: '1',
331
+ clientId: 'the_client_id',
332
+ scopes: ['user', 'oauth'],
333
+ userId: 'pwd_user_id',
325
334
  });
326
335
  oAuth2AccessToken.create.mockResolvedValueOnce({
327
336
  token: 'an_access_token',
@@ -344,61 +353,249 @@ describe('OAuth2 server', () => {
344
353
  grant_type: 'password',
345
354
  username: 'me@example.com',
346
355
  password: 'udelawli',
347
- scope: 'user',
356
+ scope: 'user invalid_scope',
348
357
  },
349
358
  validateStatus: () => true,
350
359
  });
351
360
 
352
361
  expect({
353
- status,
354
- headers: {
355
- ...headers,
356
- // Erasing the Date header that may be added by Axios :/
357
- date: undefined,
358
- etag: undefined,
359
- 'last-modified': undefined,
360
- server: undefined,
361
- connection: undefined,
362
- 'keep-alive': undefined,
362
+ response: {
363
+ status,
364
+ headers: {
365
+ ...headers,
366
+ // Erasing the Date header that may be added by Axios :/
367
+ date: undefined,
368
+ etag: undefined,
369
+ 'last-modified': undefined,
370
+ server: undefined,
371
+ connection: undefined,
372
+ 'keep-alive': undefined,
373
+ },
374
+ data,
363
375
  },
364
- data,
376
+ readClientGrantsCalls: readClientGrants.mock.calls,
377
+ authenticationCheckCalls: authentication.check.mock.calls,
378
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
379
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
380
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
381
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
382
+ oAuth2AuthorizationCodeCheckCalls:
383
+ oAuth2AuthorizationCode.check.mock.calls,
384
+ oAuth2AuthorizationCodeCreateCalls:
385
+ oAuth2AuthorizationCode.create.mock.calls,
386
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
365
387
  }).toMatchInlineSnapshot(`
366
388
  {
367
- "data": {
368
- "access_token": "an_access_token",
369
- "expiration_date": "2010-03-07T00:00:00.000Z",
370
- "expires_in": 86400,
371
- "refresh_token": "a_refresh_token",
372
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
373
- "refresh_token_expires_in": 5364748800,
374
- "token_type": "bearer",
389
+ "authenticationCheckCalls": [
390
+ [
391
+ "basic",
392
+ {
393
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
394
+ "password": "open_sesame",
395
+ "username": "ali",
396
+ },
397
+ ],
398
+ ],
399
+ "oAuth2AccessTokenCheckCalls": [],
400
+ "oAuth2AccessTokenCreateCalls": [
401
+ [
402
+ {
403
+ "clientId": "the_client_id",
404
+ "scopes": [
405
+ "user",
406
+ ],
407
+ "userId": "pwd_user_id",
408
+ },
409
+ ],
410
+ ],
411
+ "oAuth2AuthorizationCodeCheckCalls": [],
412
+ "oAuth2AuthorizationCodeCreateCalls": [],
413
+ "oAuth2PasswordCheckCalls": [
414
+ [
415
+ {
416
+ "clientId": "the_client_id",
417
+ "scopes": [
418
+ "user",
419
+ "oauth",
420
+ ],
421
+ "userId": "auth_user_id",
422
+ },
423
+ "me@example.com",
424
+ "udelawli",
425
+ ],
426
+ ],
427
+ "oAuth2RefreshTokenCheckCalls": [],
428
+ "oAuth2RefreshTokenCreateCalls": [
429
+ [
430
+ {
431
+ "clientId": "the_client_id",
432
+ "scopes": [
433
+ "user",
434
+ ],
435
+ "userId": "pwd_user_id",
436
+ },
437
+ ],
438
+ ],
439
+ "readClientGrantsCalls": [
440
+ [
441
+ "the_client_id",
442
+ ],
443
+ ],
444
+ "response": {
445
+ "data": {
446
+ "access_token": "an_access_token",
447
+ "expiration_date": "2010-03-07T00:00:00.000Z",
448
+ "expires_in": 86400,
449
+ "refresh_token": "a_refresh_token",
450
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
451
+ "refresh_token_expires_in": 5364748800,
452
+ "scope": "user",
453
+ "token_type": "bearer",
454
+ },
455
+ "headers": {
456
+ "cache-control": "no-store",
457
+ "connection": undefined,
458
+ "content-type": "application/json",
459
+ "date": undefined,
460
+ "etag": undefined,
461
+ "keep-alive": undefined,
462
+ "last-modified": undefined,
463
+ "pragma": "no-cache",
464
+ "server": undefined,
465
+ "transaction-id": "0",
466
+ "transfer-encoding": "chunked",
467
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
468
+ },
469
+ "status": 200,
375
470
  },
376
- "headers": {
377
- "connection": undefined,
378
- "content-type": "application/json",
379
- "date": undefined,
380
- "etag": undefined,
381
- "keep-alive": undefined,
382
- "last-modified": undefined,
383
- "server": undefined,
384
- "transaction-id": "0",
385
- "transfer-encoding": "chunked",
386
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
387
- },
388
- "status": 200,
389
471
  }
390
472
  `);
473
+ });
474
+
475
+ test('should fail with excluded clients', async () => {
476
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
477
+ [
478
+ oAuth2AccessToken.check,
479
+ oAuth2RefreshToken.check,
480
+ oAuth2AuthorizationCode.check,
481
+ oAuth2AuthorizationCode.create,
482
+ oAuth2RefreshToken.check,
483
+ oAuth2Password.check,
484
+ oAuth2AccessToken.create,
485
+ oAuth2RefreshToken.create,
486
+ ].forEach((mock: any) =>
487
+ mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
488
+ );
489
+ authentication.check.mockResolvedValueOnce({
490
+ clientId: 'the_client_id',
491
+ scopes: ['user', 'oauth'],
492
+ userId: 'auth_user_id',
493
+ });
494
+ readClientGrants.mockResolvedValueOnce({
495
+ allowedGrantTypes: ['authorization_code'],
496
+ allowedScopes: ['user', 'oauth'],
497
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
498
+ isPublicClient: false,
499
+ authenticationData: {
500
+ clientId: 'the_client_id',
501
+ scopes: ['user', 'oauth'],
502
+ userId: 'a_user_id',
503
+ },
504
+ });
505
+
506
+ const { status, headers, data } = await axios({
507
+ method: 'post',
508
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
509
+ headers: {
510
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString(
511
+ 'base64',
512
+ )}`,
513
+ },
514
+ data: {
515
+ grant_type: 'password',
516
+ username: 'me@example.com',
517
+ password: 'udelawli',
518
+ scope: 'user',
519
+ },
520
+ validateStatus: () => true,
521
+ });
522
+
391
523
  expect({
392
- checkApplicationCalls: checkApplication.mock.calls,
524
+ response: {
525
+ status,
526
+ headers: {
527
+ ...headers,
528
+ // Erasing the Date header that may be added by Axios :/
529
+ date: undefined,
530
+ etag: undefined,
531
+ 'last-modified': undefined,
532
+ server: undefined,
533
+ connection: undefined,
534
+ 'keep-alive': undefined,
535
+ },
536
+ data,
537
+ },
538
+ readClientGrantsCalls: readClientGrants.mock.calls,
393
539
  authenticationCheckCalls: authentication.check.mock.calls,
394
540
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
395
541
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
396
542
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
397
543
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
398
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
399
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
544
+ oAuth2AuthorizationCodeCheckCalls:
545
+ oAuth2AuthorizationCode.check.mock.calls,
546
+ oAuth2AuthorizationCodeCreateCalls:
547
+ oAuth2AuthorizationCode.create.mock.calls,
400
548
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
401
- }).toMatchSnapshot();
549
+ }).toMatchInlineSnapshot(`
550
+ {
551
+ "authenticationCheckCalls": [
552
+ [
553
+ "basic",
554
+ {
555
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
556
+ "password": "open_sesame",
557
+ "username": "ali",
558
+ },
559
+ ],
560
+ ],
561
+ "oAuth2AccessTokenCheckCalls": [],
562
+ "oAuth2AccessTokenCreateCalls": [],
563
+ "oAuth2AuthorizationCodeCheckCalls": [],
564
+ "oAuth2AuthorizationCodeCreateCalls": [],
565
+ "oAuth2PasswordCheckCalls": [],
566
+ "oAuth2RefreshTokenCheckCalls": [],
567
+ "oAuth2RefreshTokenCreateCalls": [],
568
+ "readClientGrantsCalls": [
569
+ [
570
+ "the_client_id",
571
+ ],
572
+ ],
573
+ "response": {
574
+ "data": {
575
+ "error": "unauthorized_client",
576
+ "error_debug_data": {
577
+ "guruMeditation": "1",
578
+ },
579
+ "error_description": "This grant type is not supported (password).",
580
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED+whook+error+code",
581
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
582
+ },
583
+ "headers": {
584
+ "cache-control": "private",
585
+ "connection": undefined,
586
+ "content-type": "text/plain",
587
+ "date": undefined,
588
+ "etag": undefined,
589
+ "keep-alive": undefined,
590
+ "last-modified": undefined,
591
+ "server": undefined,
592
+ "transaction-id": "1",
593
+ "transfer-encoding": "chunked",
594
+ },
595
+ "status": 400,
596
+ },
597
+ }
598
+ `);
402
599
  });
403
600
  });
404
601
 
@@ -407,27 +604,32 @@ describe('OAuth2 server', () => {
407
604
  time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
408
605
  [
409
606
  oAuth2AccessToken.check,
410
- oAuth2Code.check,
411
- oAuth2Code.create,
607
+ oAuth2AuthorizationCode.check,
608
+ oAuth2AuthorizationCode.create,
412
609
  oAuth2Password.check,
413
610
  ].forEach((mock) =>
414
611
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
415
612
  );
416
613
  authentication.check.mockResolvedValueOnce({
417
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
418
- scope: 'user,oauth',
419
- userId: '2',
614
+ clientId: 'the_client_id',
615
+ scopes: ['user', 'oauth'],
616
+ userId: 'auth_user_id',
420
617
  });
421
- checkApplication.mockResolvedValueOnce({
422
- type: 'code',
423
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
424
- scope: 'user,oauth',
425
- redirectURI: 'http://redirect.example.com/yolo',
618
+ readClientGrants.mockResolvedValueOnce({
619
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
620
+ allowedScopes: ['user', 'oauth'],
621
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
622
+ isPublicClient: false,
623
+ authenticationData: {
624
+ clientId: 'the_client_id',
625
+ scopes: ['user', 'oauth'],
626
+ userId: 'a_user_id',
627
+ },
426
628
  });
427
629
  oAuth2RefreshToken.check.mockResolvedValueOnce({
428
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
429
- scope: 'user,auth',
430
- userId: '1',
630
+ clientId: 'the_client_id',
631
+ scopes: ['user', 'oauth'],
632
+ userId: 'a_user_id',
431
633
  });
432
634
  oAuth2AccessToken.create.mockResolvedValueOnce({
433
635
  token: 'an_access_token',
@@ -455,55 +657,368 @@ describe('OAuth2 server', () => {
455
657
  });
456
658
 
457
659
  expect({
458
- status,
459
- headers: {
460
- ...headers,
461
- // Erasing the Date header that may be added by Axios :/
462
- date: undefined,
463
- etag: undefined,
464
- 'last-modified': undefined,
465
- server: undefined,
466
- connection: undefined,
467
- 'keep-alive': undefined,
660
+ response: {
661
+ status,
662
+ headers: {
663
+ ...headers,
664
+ // Erasing the Date header that may be added by Axios :/
665
+ date: undefined,
666
+ etag: undefined,
667
+ 'last-modified': undefined,
668
+ server: undefined,
669
+ connection: undefined,
670
+ 'keep-alive': undefined,
671
+ },
672
+ data,
468
673
  },
469
- data,
674
+ readClientGrantsCalls: readClientGrants.mock.calls,
675
+ authenticationCheckCalls: authentication.check.mock.calls,
676
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
677
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
678
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
679
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
680
+ oAuth2AuthorizationCodeCheckCalls:
681
+ oAuth2AuthorizationCode.check.mock.calls,
682
+ oAuth2AuthorizationCodeCreateCalls:
683
+ oAuth2AuthorizationCode.create.mock.calls,
684
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
470
685
  }).toMatchInlineSnapshot(`
471
686
  {
472
- "data": {
473
- "access_token": "an_access_token",
474
- "expiration_date": "2010-03-07T00:00:00.000Z",
475
- "expires_in": 86400,
476
- "refresh_token": "a_refresh_token",
477
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
478
- "refresh_token_expires_in": 5364748800,
479
- "token_type": "bearer",
687
+ "authenticationCheckCalls": [
688
+ [
689
+ "basic",
690
+ {
691
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
692
+ "password": "open_sesame",
693
+ "username": "ali",
694
+ },
695
+ ],
696
+ ],
697
+ "oAuth2AccessTokenCheckCalls": [],
698
+ "oAuth2AccessTokenCreateCalls": [
699
+ [
700
+ {
701
+ "clientId": "the_client_id",
702
+ "scopes": [
703
+ "user",
704
+ ],
705
+ "userId": "a_user_id",
706
+ },
707
+ ],
708
+ ],
709
+ "oAuth2AuthorizationCodeCheckCalls": [],
710
+ "oAuth2AuthorizationCodeCreateCalls": [],
711
+ "oAuth2PasswordCheckCalls": [],
712
+ "oAuth2RefreshTokenCheckCalls": [
713
+ [
714
+ "a_refresh_token",
715
+ ],
716
+ ],
717
+ "oAuth2RefreshTokenCreateCalls": [
718
+ [
719
+ {
720
+ "clientId": "the_client_id",
721
+ "scopes": [
722
+ "user",
723
+ ],
724
+ "userId": "a_user_id",
725
+ },
726
+ ],
727
+ ],
728
+ "readClientGrantsCalls": [
729
+ [
730
+ "the_client_id",
731
+ ],
732
+ ],
733
+ "response": {
734
+ "data": {
735
+ "access_token": "an_access_token",
736
+ "expiration_date": "2010-03-07T00:00:00.000Z",
737
+ "expires_in": 86400,
738
+ "refresh_token": "a_refresh_token",
739
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
740
+ "refresh_token_expires_in": 5364748800,
741
+ "scope": "user",
742
+ "token_type": "bearer",
743
+ },
744
+ "headers": {
745
+ "cache-control": "no-store",
746
+ "connection": undefined,
747
+ "content-type": "application/json",
748
+ "date": undefined,
749
+ "etag": undefined,
750
+ "keep-alive": undefined,
751
+ "last-modified": undefined,
752
+ "pragma": "no-cache",
753
+ "server": undefined,
754
+ "transaction-id": "2",
755
+ "transfer-encoding": "chunked",
756
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
757
+ },
758
+ "status": 200,
480
759
  },
481
- "headers": {
482
- "connection": undefined,
483
- "content-type": "application/json",
484
- "date": undefined,
485
- "etag": undefined,
486
- "keep-alive": undefined,
487
- "last-modified": undefined,
488
- "server": undefined,
489
- "transaction-id": "1",
490
- "transfer-encoding": "chunked",
491
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
760
+ }
761
+ `);
762
+ });
763
+
764
+ test('should fail with excluded apps', async () => {
765
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
766
+ [
767
+ oAuth2AccessToken.check,
768
+ oAuth2AuthorizationCode.check,
769
+ oAuth2AuthorizationCode.create,
770
+ oAuth2Password.check,
771
+ oAuth2AccessToken.create,
772
+ oAuth2RefreshToken.create,
773
+ ].forEach((mock) =>
774
+ mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
775
+ );
776
+ authentication.check.mockResolvedValueOnce({
777
+ clientId: 'the_client_id',
778
+ scopes: ['user', 'oauth'],
779
+ userId: 'auth_user_id',
780
+ });
781
+ readClientGrants.mockResolvedValueOnce({
782
+ allowedGrantTypes: ['authorization_code'],
783
+ allowedScopes: ['user', 'oauth'],
784
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
785
+ isPublicClient: false,
786
+ authenticationData: {
787
+ clientId: 'the_client_id',
788
+ scopes: ['user', 'oauth'],
789
+ userId: 'a_user_id',
790
+ },
791
+ });
792
+ oAuth2RefreshToken.check.mockResolvedValueOnce({
793
+ clientId: 'the_client_id',
794
+ scopes: ['user', 'oauth'],
795
+ userId: 'refresh_user_id',
796
+ });
797
+
798
+ const { status, headers, data } = await axios({
799
+ method: 'post',
800
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
801
+ headers: {
802
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString(
803
+ 'base64',
804
+ )}`,
805
+ },
806
+ data: {
807
+ grant_type: 'refresh_token',
808
+ refresh_token: 'a_refresh_token',
809
+ scope: 'user',
810
+ },
811
+ validateStatus: () => true,
812
+ });
813
+
814
+ expect({
815
+ response: {
816
+ status,
817
+ headers: {
818
+ ...headers,
819
+ // Erasing the Date header that may be added by Axios :/
820
+ date: undefined,
821
+ etag: undefined,
822
+ 'last-modified': undefined,
823
+ server: undefined,
824
+ connection: undefined,
825
+ 'keep-alive': undefined,
826
+ },
827
+ data,
828
+ },
829
+ readClientGrantsCalls: readClientGrants.mock.calls,
830
+ authenticationCheckCalls: authentication.check.mock.calls,
831
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
832
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
833
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
834
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
835
+ oAuth2AuthorizationCodeCheckCalls:
836
+ oAuth2AuthorizationCode.check.mock.calls,
837
+ oAuth2AuthorizationCodeCreateCalls:
838
+ oAuth2AuthorizationCode.create.mock.calls,
839
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
840
+ }).toMatchInlineSnapshot(`
841
+ {
842
+ "authenticationCheckCalls": [
843
+ [
844
+ "basic",
845
+ {
846
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
847
+ "password": "open_sesame",
848
+ "username": "ali",
849
+ },
850
+ ],
851
+ ],
852
+ "oAuth2AccessTokenCheckCalls": [],
853
+ "oAuth2AccessTokenCreateCalls": [],
854
+ "oAuth2AuthorizationCodeCheckCalls": [],
855
+ "oAuth2AuthorizationCodeCreateCalls": [],
856
+ "oAuth2PasswordCheckCalls": [],
857
+ "oAuth2RefreshTokenCheckCalls": [
858
+ [
859
+ "a_refresh_token",
860
+ ],
861
+ ],
862
+ "oAuth2RefreshTokenCreateCalls": [],
863
+ "readClientGrantsCalls": [
864
+ [
865
+ "the_client_id",
866
+ ],
867
+ ],
868
+ "response": {
869
+ "data": {
870
+ "error": "unauthorized_client",
871
+ "error_debug_data": {
872
+ "guruMeditation": "3",
873
+ },
874
+ "error_description": "This grant type is not supported (refresh_token).",
875
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED+whook+error+code",
876
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
877
+ },
878
+ "headers": {
879
+ "cache-control": "private",
880
+ "connection": undefined,
881
+ "content-type": "text/plain",
882
+ "date": undefined,
883
+ "etag": undefined,
884
+ "keep-alive": undefined,
885
+ "last-modified": undefined,
886
+ "server": undefined,
887
+ "transaction-id": "3",
888
+ "transfer-encoding": "chunked",
889
+ },
890
+ "status": 400,
492
891
  },
493
- "status": 200,
494
892
  }
495
893
  `);
894
+ });
895
+
896
+ test('should fail with application id mismatch', async () => {
897
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
898
+ [
899
+ oAuth2AccessToken.check,
900
+ oAuth2AuthorizationCode.check,
901
+ oAuth2AuthorizationCode.create,
902
+ oAuth2Password.check,
903
+ oAuth2AccessToken.create,
904
+ oAuth2RefreshToken.create,
905
+ ].forEach((mock) =>
906
+ mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
907
+ );
908
+ authentication.check.mockResolvedValueOnce({
909
+ clientId: 'another_client_id',
910
+ scopes: ['user', 'oauth'],
911
+ userId: 'auth_user_id',
912
+ });
913
+ readClientGrants.mockResolvedValueOnce({
914
+ allowedGrantTypes: ['authorization_code'],
915
+ allowedScopes: ['user', 'oauth'],
916
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
917
+ isPublicClient: false,
918
+ authenticationData: {
919
+ clientId: 'the_client_id',
920
+ scopes: ['user', 'oauth'],
921
+ userId: 'a_user_id',
922
+ },
923
+ });
924
+ oAuth2RefreshToken.check.mockResolvedValueOnce({
925
+ clientId: 'the_client_id',
926
+ scopes: ['user', 'oauth'],
927
+ userId: 'refresh_user_id',
928
+ });
929
+
930
+ const { status, headers, data } = await axios({
931
+ method: 'post',
932
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
933
+ headers: {
934
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString(
935
+ 'base64',
936
+ )}`,
937
+ },
938
+ data: {
939
+ grant_type: 'refresh_token',
940
+ refresh_token: 'a_refresh_token',
941
+ scope: 'user',
942
+ },
943
+ validateStatus: () => true,
944
+ });
945
+
496
946
  expect({
497
- checkApplicationCalls: checkApplication.mock.calls,
947
+ response: {
948
+ status,
949
+ headers: {
950
+ ...headers,
951
+ // Erasing the Date header that may be added by Axios :/
952
+ date: undefined,
953
+ etag: undefined,
954
+ 'last-modified': undefined,
955
+ server: undefined,
956
+ connection: undefined,
957
+ 'keep-alive': undefined,
958
+ },
959
+ data,
960
+ },
961
+ readClientGrantsCalls: readClientGrants.mock.calls,
498
962
  authenticationCheckCalls: authentication.check.mock.calls,
499
963
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
500
964
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
501
965
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
502
966
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
503
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
504
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
967
+ oAuth2AuthorizationCodeCheckCalls:
968
+ oAuth2AuthorizationCode.check.mock.calls,
969
+ oAuth2AuthorizationCodeCreateCalls:
970
+ oAuth2AuthorizationCode.create.mock.calls,
505
971
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
506
- }).toMatchSnapshot();
972
+ }).toMatchInlineSnapshot(`
973
+ {
974
+ "authenticationCheckCalls": [
975
+ [
976
+ "basic",
977
+ {
978
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
979
+ "password": "open_sesame",
980
+ "username": "ali",
981
+ },
982
+ ],
983
+ ],
984
+ "oAuth2AccessTokenCheckCalls": [],
985
+ "oAuth2AccessTokenCreateCalls": [],
986
+ "oAuth2AuthorizationCodeCheckCalls": [],
987
+ "oAuth2AuthorizationCodeCreateCalls": [],
988
+ "oAuth2PasswordCheckCalls": [],
989
+ "oAuth2RefreshTokenCheckCalls": [
990
+ [
991
+ "a_refresh_token",
992
+ ],
993
+ ],
994
+ "oAuth2RefreshTokenCreateCalls": [],
995
+ "readClientGrantsCalls": [],
996
+ "response": {
997
+ "data": {
998
+ "error": "invalid_request",
999
+ "error_debug_data": {
1000
+ "guruMeditation": "4",
1001
+ },
1002
+ "error_description": "The client used is not matching the request.",
1003
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_CLIENT_MISMATCH+whook+error+code",
1004
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_CLIENT_MISMATCH",
1005
+ },
1006
+ "headers": {
1007
+ "cache-control": "private",
1008
+ "connection": undefined,
1009
+ "content-type": "text/plain",
1010
+ "date": undefined,
1011
+ "etag": undefined,
1012
+ "keep-alive": undefined,
1013
+ "last-modified": undefined,
1014
+ "server": undefined,
1015
+ "transaction-id": "4",
1016
+ "transfer-encoding": "chunked",
1017
+ },
1018
+ "status": 400,
1019
+ },
1020
+ }
1021
+ `);
507
1022
  });
508
1023
  });
509
1024
 
@@ -513,22 +1028,27 @@ describe('OAuth2 server', () => {
513
1028
  [
514
1029
  oAuth2AccessToken.check,
515
1030
  oAuth2RefreshToken.check,
516
- oAuth2Code.check,
517
- oAuth2Code.create,
1031
+ oAuth2AuthorizationCode.check,
1032
+ oAuth2AuthorizationCode.create,
518
1033
  oAuth2Password.check,
519
1034
  ].forEach((mock) =>
520
1035
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
521
1036
  );
522
1037
  authentication.check.mockResolvedValueOnce({
523
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
524
- scope: 'user,oauth',
525
- userId: '2',
1038
+ clientId: 'the_client_id',
1039
+ scopes: ['user', 'oauth'],
1040
+ userId: 'auth_user_id',
526
1041
  });
527
- checkApplication.mockResolvedValueOnce({
528
- type: 'code',
529
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
530
- scope: 'user,oauth',
531
- redirectURI: 'http://redirect.example.com/yolo',
1042
+ readClientGrants.mockResolvedValueOnce({
1043
+ allowedGrantTypes: ['authorization_code', 'client_credentials'],
1044
+ allowedScopes: ['user', 'oauth'],
1045
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1046
+ isPublicClient: false,
1047
+ authenticationData: {
1048
+ clientId: 'the_client_id',
1049
+ scopes: ['user', 'oauth'],
1050
+ userId: 'a_user_id',
1051
+ },
532
1052
  });
533
1053
  oAuth2AccessToken.create.mockResolvedValueOnce({
534
1054
  token: 'an_access_token',
@@ -555,55 +1075,213 @@ describe('OAuth2 server', () => {
555
1075
  });
556
1076
 
557
1077
  expect({
558
- status,
559
- headers: {
560
- ...headers,
561
- // Erasing the Date header that may be added by Axios :/
562
- date: undefined,
563
- etag: undefined,
564
- 'last-modified': undefined,
565
- server: undefined,
566
- connection: undefined,
567
- 'keep-alive': undefined,
1078
+ response: {
1079
+ status,
1080
+ headers: {
1081
+ ...headers,
1082
+ // Erasing the Date header that may be added by Axios :/
1083
+ date: undefined,
1084
+ etag: undefined,
1085
+ 'last-modified': undefined,
1086
+ server: undefined,
1087
+ connection: undefined,
1088
+ 'keep-alive': undefined,
1089
+ },
1090
+ data,
568
1091
  },
569
- data,
1092
+ readClientGrantsCalls: readClientGrants.mock.calls,
1093
+ authenticationCheckCalls: authentication.check.mock.calls,
1094
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
1095
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
1096
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
1097
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
1098
+ oAuth2AuthorizationCodeCheckCalls:
1099
+ oAuth2AuthorizationCode.check.mock.calls,
1100
+ oAuth2AuthorizationCodeCreateCalls:
1101
+ oAuth2AuthorizationCode.create.mock.calls,
1102
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
570
1103
  }).toMatchInlineSnapshot(`
571
1104
  {
572
- "data": {
573
- "access_token": "an_access_token",
574
- "expiration_date": "2010-03-07T00:00:00.000Z",
575
- "expires_in": 86400,
576
- "refresh_token": "a_refresh_token",
577
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
578
- "refresh_token_expires_in": 5364748800,
579
- "token_type": "bearer",
1105
+ "authenticationCheckCalls": [
1106
+ [
1107
+ "basic",
1108
+ {
1109
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
1110
+ "password": "open_sesame",
1111
+ "username": "ali",
1112
+ },
1113
+ ],
1114
+ ],
1115
+ "oAuth2AccessTokenCheckCalls": [],
1116
+ "oAuth2AccessTokenCreateCalls": [
1117
+ [
1118
+ {
1119
+ "clientId": "the_client_id",
1120
+ "scopes": [
1121
+ "user",
1122
+ ],
1123
+ "userId": "auth_user_id",
1124
+ },
1125
+ ],
1126
+ ],
1127
+ "oAuth2AuthorizationCodeCheckCalls": [],
1128
+ "oAuth2AuthorizationCodeCreateCalls": [],
1129
+ "oAuth2PasswordCheckCalls": [],
1130
+ "oAuth2RefreshTokenCheckCalls": [],
1131
+ "oAuth2RefreshTokenCreateCalls": [],
1132
+ "readClientGrantsCalls": [
1133
+ [
1134
+ "the_client_id",
1135
+ ],
1136
+ ],
1137
+ "response": {
1138
+ "data": {
1139
+ "access_token": "an_access_token",
1140
+ "expiration_date": "2010-03-07T00:00:00.000Z",
1141
+ "expires_in": 86400,
1142
+ "scope": "user",
1143
+ "token_type": "bearer",
1144
+ },
1145
+ "headers": {
1146
+ "cache-control": "no-store",
1147
+ "connection": undefined,
1148
+ "content-type": "application/json",
1149
+ "date": undefined,
1150
+ "etag": undefined,
1151
+ "keep-alive": undefined,
1152
+ "last-modified": undefined,
1153
+ "pragma": "no-cache",
1154
+ "server": undefined,
1155
+ "transaction-id": "5",
1156
+ "transfer-encoding": "chunked",
1157
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1158
+ },
1159
+ "status": 200,
580
1160
  },
581
- "headers": {
582
- "connection": undefined,
583
- "content-type": "application/json",
584
- "date": undefined,
585
- "etag": undefined,
586
- "keep-alive": undefined,
587
- "last-modified": undefined,
588
- "server": undefined,
589
- "transaction-id": "2",
590
- "transfer-encoding": "chunked",
591
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
592
- },
593
- "status": 200,
594
1161
  }
595
1162
  `);
1163
+ });
1164
+ test('should fail with excluded apps', async () => {
1165
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
1166
+ [
1167
+ oAuth2AccessToken.check,
1168
+ oAuth2RefreshToken.check,
1169
+ oAuth2AuthorizationCode.check,
1170
+ oAuth2AuthorizationCode.create,
1171
+ oAuth2Password.check,
1172
+ oAuth2AccessToken.create,
1173
+ oAuth2RefreshToken.create,
1174
+ ].forEach((mock) =>
1175
+ mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
1176
+ );
1177
+ authentication.check.mockResolvedValueOnce({
1178
+ clientId: 'the_client_id',
1179
+ scopes: ['user', 'oauth'],
1180
+ userId: 'auth_user_id',
1181
+ });
1182
+ readClientGrants.mockResolvedValueOnce({
1183
+ allowedGrantTypes: ['authorization_code'],
1184
+ allowedScopes: ['user', 'oauth'],
1185
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1186
+ isPublicClient: false,
1187
+ authenticationData: {
1188
+ clientId: 'the_client_id',
1189
+ scopes: ['user', 'oauth'],
1190
+ userId: 'a_user_id',
1191
+ },
1192
+ });
1193
+
1194
+ const { status, headers, data } = await axios({
1195
+ method: 'post',
1196
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
1197
+ headers: {
1198
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString(
1199
+ 'base64',
1200
+ )}`,
1201
+ },
1202
+ data: {
1203
+ grant_type: 'client_credentials',
1204
+ scope: 'user',
1205
+ },
1206
+ validateStatus: () => true,
1207
+ });
1208
+
596
1209
  expect({
597
- checkApplicationCalls: checkApplication.mock.calls,
1210
+ response: {
1211
+ status,
1212
+ headers: {
1213
+ ...headers,
1214
+ // Erasing the Date header that may be added by Axios :/
1215
+ date: undefined,
1216
+ etag: undefined,
1217
+ 'last-modified': undefined,
1218
+ server: undefined,
1219
+ connection: undefined,
1220
+ 'keep-alive': undefined,
1221
+ },
1222
+ data,
1223
+ },
1224
+ readClientGrantsCalls: readClientGrants.mock.calls,
598
1225
  authenticationCheckCalls: authentication.check.mock.calls,
599
1226
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
600
1227
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
601
1228
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
602
1229
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
603
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
604
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1230
+ oAuth2AuthorizationCodeCheckCalls:
1231
+ oAuth2AuthorizationCode.check.mock.calls,
1232
+ oAuth2AuthorizationCodeCreateCalls:
1233
+ oAuth2AuthorizationCode.create.mock.calls,
605
1234
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
606
- }).toMatchSnapshot();
1235
+ }).toMatchInlineSnapshot(`
1236
+ {
1237
+ "authenticationCheckCalls": [
1238
+ [
1239
+ "basic",
1240
+ {
1241
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
1242
+ "password": "open_sesame",
1243
+ "username": "ali",
1244
+ },
1245
+ ],
1246
+ ],
1247
+ "oAuth2AccessTokenCheckCalls": [],
1248
+ "oAuth2AccessTokenCreateCalls": [],
1249
+ "oAuth2AuthorizationCodeCheckCalls": [],
1250
+ "oAuth2AuthorizationCodeCreateCalls": [],
1251
+ "oAuth2PasswordCheckCalls": [],
1252
+ "oAuth2RefreshTokenCheckCalls": [],
1253
+ "oAuth2RefreshTokenCreateCalls": [],
1254
+ "readClientGrantsCalls": [
1255
+ [
1256
+ "the_client_id",
1257
+ ],
1258
+ ],
1259
+ "response": {
1260
+ "data": {
1261
+ "error": "unauthorized_client",
1262
+ "error_debug_data": {
1263
+ "guruMeditation": "6",
1264
+ },
1265
+ "error_description": "This grant type is not supported (client_credentials).",
1266
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED+whook+error+code",
1267
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
1268
+ },
1269
+ "headers": {
1270
+ "cache-control": "private",
1271
+ "connection": undefined,
1272
+ "content-type": "text/plain",
1273
+ "date": undefined,
1274
+ "etag": undefined,
1275
+ "keep-alive": undefined,
1276
+ "last-modified": undefined,
1277
+ "server": undefined,
1278
+ "transaction-id": "6",
1279
+ "transfer-encoding": "chunked",
1280
+ },
1281
+ "status": 400,
1282
+ },
1283
+ }
1284
+ `);
607
1285
  });
608
1286
  });
609
1287
 
@@ -616,18 +1294,24 @@ describe('OAuth2 server', () => {
616
1294
  oAuth2AccessToken.create,
617
1295
  oAuth2RefreshToken.check,
618
1296
  oAuth2RefreshToken.create,
619
- oAuth2Code.check,
620
- oAuth2Code.create,
1297
+ oAuth2AuthorizationCode.check,
1298
+ oAuth2AuthorizationCode.create,
621
1299
  oAuth2Password.check,
622
1300
  ].forEach((mock) =>
623
1301
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
624
1302
  );
625
- checkApplication.mockResolvedValueOnce({
626
- type: 'code',
627
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
628
- scope: 'user,oauth',
629
- redirectURI:
1303
+ readClientGrants.mockResolvedValueOnce({
1304
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
1305
+ allowedScopes: ['user', 'oauth'],
1306
+ allowedRedirectURIS: [
630
1307
  'https://redirect.example.com/oauth2/callback?a_param=a_param_value',
1308
+ ],
1309
+ isPublicClient: false,
1310
+ authenticationData: {
1311
+ clientId: 'the_client_id',
1312
+ scopes: ['user', 'oauth'],
1313
+ userId: 'a_user_id',
1314
+ },
631
1315
  });
632
1316
 
633
1317
  const { status, headers, data } = await axios({
@@ -635,9 +1319,9 @@ describe('OAuth2 server', () => {
635
1319
  url: `http://${HOST}:${PORT}${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`,
636
1320
  params: {
637
1321
  response_type: 'code',
638
- client_id: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1322
+ client_id: 'the_client_id',
639
1323
  redirect_uri:
640
- 'https://example.com/oauth2/callback?a_param=a_param_value',
1324
+ 'https://redirect.example.com/oauth2/callback?a_param=a_param_value',
641
1325
  scope: 'user',
642
1326
  state: 'xyz',
643
1327
  },
@@ -646,46 +1330,63 @@ describe('OAuth2 server', () => {
646
1330
  });
647
1331
 
648
1332
  expect({
649
- status,
650
- headers: {
651
- ...headers,
652
- // Erasing the Date header that may be added by Axios :/
653
- date: undefined,
654
- etag: undefined,
655
- 'last-modified': undefined,
656
- server: undefined,
657
- connection: undefined,
658
- 'keep-alive': undefined,
1333
+ response: {
1334
+ status,
1335
+ headers: {
1336
+ ...headers,
1337
+ // Erasing the Date header that may be added by Axios :/
1338
+ date: undefined,
1339
+ etag: undefined,
1340
+ 'last-modified': undefined,
1341
+ server: undefined,
1342
+ connection: undefined,
1343
+ 'keep-alive': undefined,
1344
+ },
1345
+ data,
659
1346
  },
660
- data,
661
- }).toMatchInlineSnapshot(`
662
- {
663
- "data": "",
664
- "headers": {
665
- "connection": undefined,
666
- "date": undefined,
667
- "etag": undefined,
668
- "keep-alive": undefined,
669
- "last-modified": undefined,
670
- "location": "https://auth.example.com/sign_in?type=code&redirect_uri=https%3A%2F%2Fredirect.example.com%2Foauth2%2Fcallback%3Fa_param%3Da_param_value&scope=user&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&state=xyz",
671
- "server": undefined,
672
- "transaction-id": "3",
673
- "transfer-encoding": "chunked",
674
- },
675
- "status": 302,
676
- }
677
- `);
678
- expect({
679
- checkApplicationCalls: checkApplication.mock.calls,
1347
+ readClientGrantsCalls: readClientGrants.mock.calls,
680
1348
  authenticationCheckCalls: authentication.check.mock.calls,
681
1349
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
682
1350
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
683
1351
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
684
1352
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
685
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
686
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1353
+ oAuth2AuthorizationCodeCheckCalls:
1354
+ oAuth2AuthorizationCode.check.mock.calls,
1355
+ oAuth2AuthorizationCodeCreateCalls:
1356
+ oAuth2AuthorizationCode.create.mock.calls,
687
1357
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
688
- }).toMatchSnapshot();
1358
+ }).toMatchInlineSnapshot(`
1359
+ {
1360
+ "authenticationCheckCalls": [],
1361
+ "oAuth2AccessTokenCheckCalls": [],
1362
+ "oAuth2AccessTokenCreateCalls": [],
1363
+ "oAuth2AuthorizationCodeCheckCalls": [],
1364
+ "oAuth2AuthorizationCodeCreateCalls": [],
1365
+ "oAuth2PasswordCheckCalls": [],
1366
+ "oAuth2RefreshTokenCheckCalls": [],
1367
+ "oAuth2RefreshTokenCreateCalls": [],
1368
+ "readClientGrantsCalls": [
1369
+ [
1370
+ "the_client_id",
1371
+ ],
1372
+ ],
1373
+ "response": {
1374
+ "data": "",
1375
+ "headers": {
1376
+ "connection": undefined,
1377
+ "date": undefined,
1378
+ "etag": undefined,
1379
+ "keep-alive": undefined,
1380
+ "last-modified": undefined,
1381
+ "location": "https://auth.example.com/sign_in?type=code&redirect_uri=https%3A%2F%2Fredirect.example.com%2Foauth2%2Fcallback%3Fa_param%3Da_param_value&scope=user&client_id=the_client_id&state=xyz",
1382
+ "server": undefined,
1383
+ "transaction-id": "7",
1384
+ "transfer-encoding": "chunked",
1385
+ },
1386
+ "status": 302,
1387
+ },
1388
+ }
1389
+ `);
689
1390
  });
690
1391
 
691
1392
  test('should redirect with a code', async () => {
@@ -695,22 +1396,41 @@ describe('OAuth2 server', () => {
695
1396
  oAuth2AccessToken.create,
696
1397
  oAuth2RefreshToken.check,
697
1398
  oAuth2RefreshToken.create,
698
- oAuth2Code.check,
1399
+ oAuth2AuthorizationCode.check,
699
1400
  oAuth2Password.check,
700
1401
  ].forEach((mock) =>
701
1402
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
702
1403
  );
703
1404
  authentication.check.mockResolvedValueOnce({
704
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
705
- scope: 'user,oauth',
706
- userId: '2',
1405
+ clientId: 'the_root_client_id',
1406
+ scopes: ['user', 'oauth'],
1407
+ userId: 'auth_user_id',
707
1408
  });
708
- oAuth2Code.create.mockResolvedValueOnce('a_code');
709
- checkApplication.mockResolvedValueOnce({
710
- type: 'code',
711
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
712
- scope: 'user,oauth',
713
- redirectURI: 'http://redirect.example.com/yolo',
1409
+ oAuth2AuthorizationCode.create.mockResolvedValueOnce('a_code');
1410
+ readClientGrants.mockResolvedValueOnce({
1411
+ allowedGrantTypes: ['password'],
1412
+ allowedScopes: [],
1413
+ allowedRedirectURIS: [],
1414
+ isPublicClient: false,
1415
+ canAcknowledge: true,
1416
+ authenticationData: {
1417
+ clientId: 'the_root_client_id',
1418
+ scopes: [],
1419
+ userId: 'a_user_id',
1420
+ },
1421
+ });
1422
+ readClientGrants.mockResolvedValueOnce({
1423
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
1424
+ allowedScopes: ['user', 'oauth'],
1425
+ allowedRedirectURIS: [
1426
+ 'http://redirect.example.com/yolo?a_param=a_value',
1427
+ ],
1428
+ isPublicClient: false,
1429
+ authenticationData: {
1430
+ clientId: 'the_client_id',
1431
+ scopes: ['user', 'oauth'],
1432
+ userId: 'a_user_id',
1433
+ },
714
1434
  });
715
1435
 
716
1436
  const { status, headers, data } = await axios({
@@ -721,7 +1441,7 @@ describe('OAuth2 server', () => {
721
1441
  },
722
1442
  data: {
723
1443
  responseType: 'code',
724
- clientId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1444
+ clientId: 'the_client_id',
725
1445
  redirectURI: 'http://redirect.example.com/yolo?a_param=a_value',
726
1446
  scope: 'user',
727
1447
  state: 'xyz',
@@ -732,47 +1452,93 @@ describe('OAuth2 server', () => {
732
1452
  });
733
1453
 
734
1454
  expect({
735
- status,
736
- headers: {
737
- ...headers,
738
- // Erasing the Date header that may be added by Axios :/
739
- date: undefined,
740
- etag: undefined,
741
- 'last-modified': undefined,
742
- server: undefined,
743
- connection: undefined,
744
- 'keep-alive': undefined,
1455
+ response: {
1456
+ status,
1457
+ headers: {
1458
+ ...headers,
1459
+ // Erasing the Date header that may be added by Axios :/
1460
+ date: undefined,
1461
+ etag: undefined,
1462
+ 'last-modified': undefined,
1463
+ server: undefined,
1464
+ connection: undefined,
1465
+ 'keep-alive': undefined,
1466
+ },
1467
+ data,
745
1468
  },
746
- data,
747
- }).toMatchInlineSnapshot(`
748
- {
749
- "data": "",
750
- "headers": {
751
- "connection": undefined,
752
- "date": undefined,
753
- "etag": undefined,
754
- "keep-alive": undefined,
755
- "last-modified": undefined,
756
- "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&code=a_code",
757
- "server": undefined,
758
- "transaction-id": "4",
759
- "transfer-encoding": "chunked",
760
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
761
- },
762
- "status": 201,
763
- }
764
- `);
765
- expect({
766
- checkApplicationCalls: checkApplication.mock.calls,
1469
+ readClientGrantsCalls: readClientGrants.mock.calls,
767
1470
  authenticationCheckCalls: authentication.check.mock.calls,
768
1471
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
769
1472
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
770
1473
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
771
1474
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
772
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
773
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1475
+ oAuth2AuthorizationCodeCheckCalls:
1476
+ oAuth2AuthorizationCode.check.mock.calls,
1477
+ oAuth2AuthorizationCodeCreateCalls:
1478
+ oAuth2AuthorizationCode.create.mock.calls,
774
1479
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
775
- }).toMatchSnapshot();
1480
+ }).toMatchInlineSnapshot(`
1481
+ {
1482
+ "authenticationCheckCalls": [
1483
+ [
1484
+ "bearer",
1485
+ {
1486
+ "hash": "yolo",
1487
+ },
1488
+ ],
1489
+ ],
1490
+ "oAuth2AccessTokenCheckCalls": [],
1491
+ "oAuth2AccessTokenCreateCalls": [],
1492
+ "oAuth2AuthorizationCodeCheckCalls": [],
1493
+ "oAuth2AuthorizationCodeCreateCalls": [
1494
+ [
1495
+ {
1496
+ "clientId": "the_client_id",
1497
+ "scopes": [
1498
+ "user",
1499
+ ],
1500
+ "userId": "auth_user_id",
1501
+ },
1502
+ {
1503
+ "demandedRedirectURI": "http://redirect.example.com/yolo?a_param=a_value",
1504
+ "demandedScopes": [
1505
+ "user",
1506
+ ],
1507
+ "filteredScopes": [
1508
+ "user",
1509
+ ],
1510
+ },
1511
+ ],
1512
+ ],
1513
+ "oAuth2PasswordCheckCalls": [],
1514
+ "oAuth2RefreshTokenCheckCalls": [],
1515
+ "oAuth2RefreshTokenCreateCalls": [],
1516
+ "readClientGrantsCalls": [
1517
+ [
1518
+ "the_root_client_id",
1519
+ ],
1520
+ [
1521
+ "the_client_id",
1522
+ ],
1523
+ ],
1524
+ "response": {
1525
+ "data": "",
1526
+ "headers": {
1527
+ "connection": undefined,
1528
+ "date": undefined,
1529
+ "etag": undefined,
1530
+ "keep-alive": undefined,
1531
+ "last-modified": undefined,
1532
+ "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=the_client_id&scope=user&state=xyz&code=a_code",
1533
+ "server": undefined,
1534
+ "transaction-id": "8",
1535
+ "transfer-encoding": "chunked",
1536
+ "x-authenticated": "{"clientId":"the_root_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1537
+ },
1538
+ "status": 201,
1539
+ },
1540
+ }
1541
+ `);
776
1542
  });
777
1543
 
778
1544
  test('should produce new tokens', async () => {
@@ -785,21 +1551,32 @@ describe('OAuth2 server', () => {
785
1551
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
786
1552
  );
787
1553
  authentication.check.mockResolvedValueOnce({
788
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
789
- scope: 'user,oauth',
790
- userId: '2',
1554
+ clientId: 'the_client_id',
1555
+ scopes: ['user', 'oauth'],
1556
+ userId: 'auth_user_id',
791
1557
  });
792
- checkApplication.mockResolvedValueOnce({
793
- type: 'code',
794
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
795
- scope: 'user,oauth',
796
- redirectURI: 'http://redirect.example.com/yolo',
1558
+ readClientGrants.mockResolvedValueOnce({
1559
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
1560
+ allowedScopes: ['user', 'oauth'],
1561
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1562
+ isPublicClient: false,
1563
+ authenticationData: {
1564
+ clientId: 'the_client_id',
1565
+ scopes: ['user', 'oauth'],
1566
+ userId: 'a_user_id',
1567
+ },
797
1568
  });
798
- oAuth2Code.check.mockResolvedValueOnce({
799
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
800
- scope: 'user,auth',
801
- userId: '1',
802
- redirectURI: 'http://redirect.example.com/yolo',
1569
+ oAuth2AuthorizationCode.check.mockResolvedValueOnce({
1570
+ codeAuthenticationData: {
1571
+ clientId: 'the_client_id',
1572
+ scopes: ['user', 'oauth'],
1573
+ userId: 'a_user_id',
1574
+ },
1575
+ context: {
1576
+ demandedRedirectURI: 'http://redirect.example.com/yolo',
1577
+ demandedScopes: ['user'],
1578
+ filteredScopes: ['user'],
1579
+ },
803
1580
  });
804
1581
  oAuth2AccessToken.create.mockResolvedValueOnce({
805
1582
  token: 'an_access_token',
@@ -827,55 +1604,116 @@ describe('OAuth2 server', () => {
827
1604
  });
828
1605
 
829
1606
  expect({
830
- status,
831
- headers: {
832
- ...headers,
833
- // Erasing the Date header that may be added by Axios :/
834
- date: undefined,
835
- etag: undefined,
836
- 'last-modified': undefined,
837
- server: undefined,
838
- connection: undefined,
839
- 'keep-alive': undefined,
1607
+ response: {
1608
+ status,
1609
+ headers: {
1610
+ ...headers,
1611
+ // Erasing the Date header that may be added by Axios :/
1612
+ date: undefined,
1613
+ etag: undefined,
1614
+ 'last-modified': undefined,
1615
+ server: undefined,
1616
+ connection: undefined,
1617
+ 'keep-alive': undefined,
1618
+ },
1619
+ data,
840
1620
  },
841
- data,
842
- }).toMatchInlineSnapshot(`
843
- {
844
- "data": {
845
- "access_token": "an_access_token",
846
- "expiration_date": "2010-03-07T00:00:00.000Z",
847
- "expires_in": 86400,
848
- "refresh_token": "a_refresh_token",
849
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
850
- "refresh_token_expires_in": 5364748800,
851
- "token_type": "bearer",
852
- },
853
- "headers": {
854
- "connection": undefined,
855
- "content-type": "application/json",
856
- "date": undefined,
857
- "etag": undefined,
858
- "keep-alive": undefined,
859
- "last-modified": undefined,
860
- "server": undefined,
861
- "transaction-id": "5",
862
- "transfer-encoding": "chunked",
863
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
864
- },
865
- "status": 200,
866
- }
867
- `);
868
- expect({
869
- checkApplicationCalls: checkApplication.mock.calls,
1621
+ readClientGrantsCalls: readClientGrants.mock.calls,
870
1622
  authenticationCheckCalls: authentication.check.mock.calls,
871
1623
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
872
1624
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
873
1625
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
874
1626
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
875
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
876
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1627
+ oAuth2AuthorizationCodeCheckCalls:
1628
+ oAuth2AuthorizationCode.check.mock.calls,
1629
+ oAuth2AuthorizationCodeCreateCalls:
1630
+ oAuth2AuthorizationCode.create.mock.calls,
877
1631
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
878
- }).toMatchSnapshot();
1632
+ }).toMatchInlineSnapshot(`
1633
+ {
1634
+ "authenticationCheckCalls": [
1635
+ [
1636
+ "basic",
1637
+ {
1638
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
1639
+ "password": "open_sesame",
1640
+ "username": "ali",
1641
+ },
1642
+ ],
1643
+ ],
1644
+ "oAuth2AccessTokenCheckCalls": [],
1645
+ "oAuth2AccessTokenCreateCalls": [
1646
+ [
1647
+ {
1648
+ "clientId": "the_client_id",
1649
+ "scopes": [
1650
+ "user",
1651
+ ],
1652
+ "userId": "a_user_id",
1653
+ },
1654
+ ],
1655
+ ],
1656
+ "oAuth2AuthorizationCodeCheckCalls": [
1657
+ [
1658
+ {
1659
+ "clientId": "the_client_id",
1660
+ "scopes": [
1661
+ "user",
1662
+ "oauth",
1663
+ ],
1664
+ "userId": "auth_user_id",
1665
+ },
1666
+ "a_grant_code",
1667
+ ],
1668
+ ],
1669
+ "oAuth2AuthorizationCodeCreateCalls": [],
1670
+ "oAuth2PasswordCheckCalls": [],
1671
+ "oAuth2RefreshTokenCheckCalls": [],
1672
+ "oAuth2RefreshTokenCreateCalls": [
1673
+ [
1674
+ {
1675
+ "clientId": "the_client_id",
1676
+ "scopes": [
1677
+ "user",
1678
+ ],
1679
+ "userId": "a_user_id",
1680
+ },
1681
+ ],
1682
+ ],
1683
+ "readClientGrantsCalls": [
1684
+ [
1685
+ "the_client_id",
1686
+ ],
1687
+ ],
1688
+ "response": {
1689
+ "data": {
1690
+ "access_token": "an_access_token",
1691
+ "expiration_date": "2010-03-07T00:00:00.000Z",
1692
+ "expires_in": 86400,
1693
+ "refresh_token": "a_refresh_token",
1694
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
1695
+ "refresh_token_expires_in": 5364748800,
1696
+ "scope": "user",
1697
+ "token_type": "bearer",
1698
+ },
1699
+ "headers": {
1700
+ "cache-control": "no-store",
1701
+ "connection": undefined,
1702
+ "content-type": "application/json",
1703
+ "date": undefined,
1704
+ "etag": undefined,
1705
+ "keep-alive": undefined,
1706
+ "last-modified": undefined,
1707
+ "pragma": "no-cache",
1708
+ "server": undefined,
1709
+ "transaction-id": "9",
1710
+ "transfer-encoding": "chunked",
1711
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1712
+ },
1713
+ "status": 200,
1714
+ },
1715
+ }
1716
+ `);
879
1717
  });
880
1718
  });
881
1719
 
@@ -888,17 +1726,22 @@ describe('OAuth2 server', () => {
888
1726
  oAuth2AccessToken.create,
889
1727
  oAuth2RefreshToken.check,
890
1728
  oAuth2RefreshToken.create,
891
- oAuth2Code.check,
892
- oAuth2Code.create,
1729
+ oAuth2AuthorizationCode.check,
1730
+ oAuth2AuthorizationCode.create,
893
1731
  oAuth2Password.check,
894
1732
  ].forEach((mock) =>
895
1733
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
896
1734
  );
897
- checkApplication.mockResolvedValueOnce({
898
- type: 'implicit',
899
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
900
- scope: 'user,oauth',
901
- redirectURI: 'http://redirect.example.com/yolo',
1735
+ readClientGrants.mockResolvedValueOnce({
1736
+ allowedGrantTypes: ['implicit'],
1737
+ allowedScopes: ['user', 'oauth'],
1738
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1739
+ isPublicClient: false,
1740
+ authenticationData: {
1741
+ clientId: 'the_client_id',
1742
+ scopes: ['user', 'oauth'],
1743
+ userId: 'a_user_id',
1744
+ },
902
1745
  });
903
1746
 
904
1747
  const { status, headers, data } = await axios({
@@ -906,7 +1749,7 @@ describe('OAuth2 server', () => {
906
1749
  url: `http://${HOST}:${PORT}${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`,
907
1750
  params: {
908
1751
  response_type: 'token',
909
- client_id: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1752
+ client_id: 'the_client_id',
910
1753
  redirect_uri: 'http://redirect.example.com/yolo',
911
1754
  scope: 'user',
912
1755
  state: 'xyz',
@@ -916,46 +1759,63 @@ describe('OAuth2 server', () => {
916
1759
  });
917
1760
 
918
1761
  expect({
919
- status,
920
- headers: {
921
- ...headers,
922
- // Erasing the Date header that may be added by Axios :/
923
- date: undefined,
924
- etag: undefined,
925
- 'last-modified': undefined,
926
- server: undefined,
927
- connection: undefined,
928
- 'keep-alive': undefined,
1762
+ response: {
1763
+ status,
1764
+ headers: {
1765
+ ...headers,
1766
+ // Erasing the Date header that may be added by Axios :/
1767
+ date: undefined,
1768
+ etag: undefined,
1769
+ 'last-modified': undefined,
1770
+ server: undefined,
1771
+ connection: undefined,
1772
+ 'keep-alive': undefined,
1773
+ },
1774
+ data,
929
1775
  },
930
- data,
931
- }).toMatchInlineSnapshot(`
932
- {
933
- "data": "",
934
- "headers": {
935
- "connection": undefined,
936
- "date": undefined,
937
- "etag": undefined,
938
- "keep-alive": undefined,
939
- "last-modified": undefined,
940
- "location": "https://auth.example.com/sign_in?type=token&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&scope=user&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&state=xyz",
941
- "server": undefined,
942
- "transaction-id": "6",
943
- "transfer-encoding": "chunked",
944
- },
945
- "status": 302,
946
- }
947
- `);
948
- expect({
949
- checkApplicationCalls: checkApplication.mock.calls,
1776
+ readClientGrantsCalls: readClientGrants.mock.calls,
950
1777
  authenticationCheckCalls: authentication.check.mock.calls,
951
1778
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
952
1779
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
953
1780
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
954
1781
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
955
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
956
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1782
+ oAuth2AuthorizationCodeCheckCalls:
1783
+ oAuth2AuthorizationCode.check.mock.calls,
1784
+ oAuth2AuthorizationCodeCreateCalls:
1785
+ oAuth2AuthorizationCode.create.mock.calls,
957
1786
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
958
- }).toMatchSnapshot();
1787
+ }).toMatchInlineSnapshot(`
1788
+ {
1789
+ "authenticationCheckCalls": [],
1790
+ "oAuth2AccessTokenCheckCalls": [],
1791
+ "oAuth2AccessTokenCreateCalls": [],
1792
+ "oAuth2AuthorizationCodeCheckCalls": [],
1793
+ "oAuth2AuthorizationCodeCreateCalls": [],
1794
+ "oAuth2PasswordCheckCalls": [],
1795
+ "oAuth2RefreshTokenCheckCalls": [],
1796
+ "oAuth2RefreshTokenCreateCalls": [],
1797
+ "readClientGrantsCalls": [
1798
+ [
1799
+ "the_client_id",
1800
+ ],
1801
+ ],
1802
+ "response": {
1803
+ "data": "",
1804
+ "headers": {
1805
+ "connection": undefined,
1806
+ "date": undefined,
1807
+ "etag": undefined,
1808
+ "keep-alive": undefined,
1809
+ "last-modified": undefined,
1810
+ "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",
1811
+ "server": undefined,
1812
+ "transaction-id": "10",
1813
+ "transfer-encoding": "chunked",
1814
+ },
1815
+ "status": 302,
1816
+ },
1817
+ }
1818
+ `);
959
1819
  });
960
1820
 
961
1821
  test('should redirect with a token', async () => {
@@ -964,32 +1824,45 @@ describe('OAuth2 server', () => {
964
1824
  oAuth2AccessToken.check,
965
1825
  oAuth2RefreshToken.check,
966
1826
  oAuth2RefreshToken.create,
967
- oAuth2Code.check,
968
- oAuth2Code.create,
1827
+ oAuth2AuthorizationCode.check,
1828
+ oAuth2AuthorizationCode.create,
969
1829
  oAuth2Password.check,
970
1830
  ].forEach((mock) =>
971
1831
  mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
972
1832
  );
973
1833
  authentication.check.mockResolvedValueOnce({
974
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
975
- scope: 'user,oauth',
976
- userId: '2',
1834
+ clientId: 'the_root_client_id',
1835
+ scopes: ['user', 'oauth'],
1836
+ userId: 'auth_user_id',
977
1837
  });
978
1838
  oAuth2AccessToken.create.mockResolvedValueOnce({
979
1839
  token: 'an_access_token',
980
1840
  expiresAt: Date.parse('2010-03-07T00:00:00Z'),
981
1841
  });
982
- checkApplication.mockResolvedValueOnce({
983
- type: 'implicit',
984
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
985
- scope: 'user,oauth',
986
- redirectURI: 'http://redirect.example.com/yolo',
1842
+ readClientGrants.mockResolvedValueOnce({
1843
+ allowedGrantTypes: ['password'],
1844
+ allowedScopes: [],
1845
+ allowedRedirectURIS: [],
1846
+ isPublicClient: false,
1847
+ canAcknowledge: true,
1848
+ authenticationData: {
1849
+ clientId: 'the_root_client_id',
1850
+ scopes: [],
1851
+ userId: 'a_user_id',
1852
+ },
987
1853
  });
988
- checkApplication.mockResolvedValueOnce({
989
- type: 'implicit',
990
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
991
- scope: 'user,oauth',
992
- redirectURI: 'http://redirect.example.com/yolo',
1854
+ readClientGrants.mockResolvedValueOnce({
1855
+ allowedGrantTypes: ['implicit'],
1856
+ allowedScopes: ['user', 'oauth'],
1857
+ allowedRedirectURIS: [
1858
+ 'http://redirect.example.com/yolo?a_param=a_value',
1859
+ ],
1860
+ isPublicClient: true,
1861
+ authenticationData: {
1862
+ clientId: 'the_client_id',
1863
+ scopes: ['user', 'oauth'],
1864
+ userId: 'a_user_id',
1865
+ },
993
1866
  });
994
1867
 
995
1868
  const { status, headers, data } = await axios({
@@ -1000,7 +1873,7 @@ describe('OAuth2 server', () => {
1000
1873
  },
1001
1874
  data: {
1002
1875
  responseType: 'token',
1003
- clientId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1876
+ clientId: 'the_client_id',
1004
1877
  redirectURI: 'http://redirect.example.com/yolo?a_param=a_value',
1005
1878
  scope: 'user',
1006
1879
  state: 'xyz',
@@ -1011,47 +1884,84 @@ describe('OAuth2 server', () => {
1011
1884
  });
1012
1885
 
1013
1886
  expect({
1014
- status,
1015
- headers: {
1016
- ...headers,
1017
- // Erasing the Date header that may be added by Axios :/
1018
- date: undefined,
1019
- etag: undefined,
1020
- 'last-modified': undefined,
1021
- server: undefined,
1022
- connection: undefined,
1023
- 'keep-alive': undefined,
1887
+ response: {
1888
+ status,
1889
+ headers: {
1890
+ ...headers,
1891
+ // Erasing the Date header that may be added by Axios :/
1892
+ date: undefined,
1893
+ etag: undefined,
1894
+ 'last-modified': undefined,
1895
+ server: undefined,
1896
+ connection: undefined,
1897
+ 'keep-alive': undefined,
1898
+ },
1899
+ data,
1024
1900
  },
1025
- data,
1026
- }).toMatchInlineSnapshot(`
1027
- {
1028
- "data": "",
1029
- "headers": {
1030
- "connection": undefined,
1031
- "date": undefined,
1032
- "etag": undefined,
1033
- "keep-alive": undefined,
1034
- "last-modified": undefined,
1035
- "location": "http://redirect.example.com/yolo?client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&access_token=an_access_token&token_type=bearer&expires_in=86400",
1036
- "server": undefined,
1037
- "transaction-id": "7",
1038
- "transfer-encoding": "chunked",
1039
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
1040
- },
1041
- "status": 201,
1042
- }
1043
- `);
1044
- expect({
1045
- checkApplicationCalls: checkApplication.mock.calls,
1901
+ readClientGrantsCalls: readClientGrants.mock.calls,
1046
1902
  authenticationCheckCalls: authentication.check.mock.calls,
1047
1903
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
1048
1904
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
1049
1905
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
1050
1906
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
1051
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
1052
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1907
+ oAuth2AuthorizationCodeCheckCalls:
1908
+ oAuth2AuthorizationCode.check.mock.calls,
1909
+ oAuth2AuthorizationCodeCreateCalls:
1910
+ oAuth2AuthorizationCode.create.mock.calls,
1053
1911
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
1054
- }).toMatchSnapshot();
1912
+ }).toMatchInlineSnapshot(`
1913
+ {
1914
+ "authenticationCheckCalls": [
1915
+ [
1916
+ "bearer",
1917
+ {
1918
+ "hash": "yolo",
1919
+ },
1920
+ ],
1921
+ ],
1922
+ "oAuth2AccessTokenCheckCalls": [],
1923
+ "oAuth2AccessTokenCreateCalls": [
1924
+ [
1925
+ {
1926
+ "clientId": "the_client_id",
1927
+ "scopes": [
1928
+ "user",
1929
+ ],
1930
+ "userId": "auth_user_id",
1931
+ },
1932
+ ],
1933
+ ],
1934
+ "oAuth2AuthorizationCodeCheckCalls": [],
1935
+ "oAuth2AuthorizationCodeCreateCalls": [],
1936
+ "oAuth2PasswordCheckCalls": [],
1937
+ "oAuth2RefreshTokenCheckCalls": [],
1938
+ "oAuth2RefreshTokenCreateCalls": [],
1939
+ "readClientGrantsCalls": [
1940
+ [
1941
+ "the_root_client_id",
1942
+ ],
1943
+ [
1944
+ "the_client_id",
1945
+ ],
1946
+ ],
1947
+ "response": {
1948
+ "data": "",
1949
+ "headers": {
1950
+ "connection": undefined,
1951
+ "date": undefined,
1952
+ "etag": undefined,
1953
+ "keep-alive": undefined,
1954
+ "last-modified": undefined,
1955
+ "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",
1956
+ "server": undefined,
1957
+ "transaction-id": "11",
1958
+ "transfer-encoding": "chunked",
1959
+ "x-authenticated": "{"clientId":"the_root_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1960
+ },
1961
+ "status": 201,
1962
+ },
1963
+ }
1964
+ `);
1055
1965
  });
1056
1966
  });
1057
1967
  });