@whook/oauth2 25.2.0 → 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 +20 -9
  40. package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
  41. package/dist/routes/getOAuth2WellKnownMetadata.test.js +38 -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 +20 -10
  62. package/dist/routes/postOAuth2Acknowledge.js +54 -38
  63. package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
  64. package/dist/routes/postOAuth2Acknowledge.test.js +137 -72
  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 +58 -60
  129. package/src/routes/getOAuth2WellKnownMetadata.ts +26 -11
  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 +169 -110
  138. package/src/routes/postOAuth2Acknowledge.ts +101 -61
  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
@@ -6,7 +6,7 @@ import { alsoInject, constant, initializer } from 'knifecycle';
6
6
  import axios from 'axios';
7
7
  import { YError } from 'yerror';
8
8
  import { BEARER as BEARER_MECHANISM, BASIC as BASIC_MECHANISM, } from 'http-auth-utils';
9
- import { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeCodeChallengeSchema, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodSchema, getOAuth2AuthorizeCodeChallengeMethodParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenCodeVerifierSchema, postOAuth2TokenDefinition, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2CodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2TokenGranter, postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, postOAuth2TokenPasswordTokenRequestBodySchema, postOAuth2TokenClientCredentialsTokenRequestBodySchema, postOAuth2TokenTokenBodySchema, postOAuth2TokenRefreshTokenRequestBodySchema, } from './index.js';
9
+ import { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeScopeSchema, getOAuth2AuthorizeCodeChallengeSchema, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodSchema, getOAuth2AuthorizeCodeChallengeMethodParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenCodeVerifierSchema, postOAuth2TokenDefinition, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2AuthorizationCodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2ImplicitGranter, postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, postOAuth2TokenPasswordTokenRequestBodySchema, postOAuth2TokenClientCredentialsTokenRequestBodySchema, postOAuth2TokenTokenBodySchema, postOAuth2TokenRefreshTokenRequestBodySchema, } from './index.js';
10
10
  describe('OAuth2 server', () => {
11
11
  const BASE_PATH = '/v1';
12
12
  const PORT = 4444;
@@ -76,13 +76,14 @@ describe('OAuth2 server', () => {
76
76
  [name]: parameter,
77
77
  }), {}),
78
78
  schemas: [
79
+ getOAuth2AuthorizeScopeSchema,
80
+ getOAuth2AuthorizeCodeChallengeSchema,
81
+ getOAuth2AuthorizeCodeChallengeMethodSchema,
79
82
  postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
80
83
  postOAuth2TokenPasswordTokenRequestBodySchema,
81
84
  postOAuth2TokenClientCredentialsTokenRequestBodySchema,
82
85
  postOAuth2TokenRefreshTokenRequestBodySchema,
83
86
  postOAuth2TokenTokenBodySchema,
84
- getOAuth2AuthorizeCodeChallengeSchema,
85
- getOAuth2AuthorizeCodeChallengeMethodSchema,
86
87
  postOAuth2TokenCodeVerifierSchema,
87
88
  ].reduce((schemasHash, { name, schema }) => ({
88
89
  ...schemasHash,
@@ -92,11 +93,13 @@ describe('OAuth2 server', () => {
92
93
  };
93
94
  const OAUTH2 = {
94
95
  authenticateURL: 'https://auth.example.com/sign_in',
96
+ allowedScopes: ['user', 'oauth'],
97
+ rootClientId: 'the_root_client_id',
95
98
  };
96
99
  const authentication = {
97
100
  check: jest.fn(),
98
101
  };
99
- const checkApplication = jest.fn();
102
+ const readClientGrants = jest.fn();
100
103
  const oAuth2AccessToken = {
101
104
  create: jest.fn(),
102
105
  check: jest.fn(),
@@ -105,7 +108,7 @@ describe('OAuth2 server', () => {
105
108
  create: jest.fn(),
106
109
  check: jest.fn(),
107
110
  };
108
- const oAuth2Code = {
111
+ const oAuth2AuthorizationCode = {
109
112
  create: jest.fn(),
110
113
  check: jest.fn(),
111
114
  };
@@ -147,10 +150,10 @@ describe('OAuth2 server', () => {
147
150
  }));
148
151
  $.register(alsoInject(['getOAuth2Authorize', 'postOAuth2Acknowledge', 'postOAuth2Token'], initRoutesHandlers));
149
152
  $.register(constant('authentication', authentication));
150
- $.register(constant('checkApplication', checkApplication));
153
+ $.register(constant('readClientGrants', readClientGrants));
151
154
  $.register(constant('oAuth2AccessToken', oAuth2AccessToken));
152
155
  $.register(constant('oAuth2RefreshToken', oAuth2RefreshToken));
153
- $.register(constant('oAuth2Code', oAuth2Code));
156
+ $.register(constant('oAuth2AuthorizationCode', oAuth2AuthorizationCode));
154
157
  $.register(constant('oAuth2Password', oAuth2Password));
155
158
  [
156
159
  initGetOAuth2Authorize,
@@ -158,10 +161,10 @@ describe('OAuth2 server', () => {
158
161
  initPostOAuth2Token,
159
162
  initOAuth2Granters,
160
163
  initOAuth2ClientCredentialsGranter,
161
- initOAuth2CodeGranter,
164
+ initOAuth2AuthorizationCodeGranter,
162
165
  initOAuth2PasswordGranter,
163
166
  initOAuth2RefreshTokenGranter,
164
- initOAuth2TokenGranter,
167
+ initOAuth2ImplicitGranter,
165
168
  ].forEach((handlerInitializer) => $.register(handlerInitializer));
166
169
  return $;
167
170
  }
@@ -191,10 +194,10 @@ describe('OAuth2 server', () => {
191
194
  oAuth2AccessToken.check,
192
195
  oAuth2RefreshToken.create,
193
196
  oAuth2RefreshToken.check,
194
- oAuth2Code.check,
195
- oAuth2Code.create,
197
+ oAuth2AuthorizationCode.check,
198
+ oAuth2AuthorizationCode.create,
196
199
  oAuth2Password.check,
197
- checkApplication,
200
+ readClientGrants,
198
201
  authentication.check,
199
202
  ].forEach((mock) => mock.mockReset());
200
203
  });
@@ -204,25 +207,30 @@ describe('OAuth2 server', () => {
204
207
  [
205
208
  oAuth2AccessToken.check,
206
209
  oAuth2RefreshToken.check,
207
- oAuth2Code.check,
208
- oAuth2Code.create,
210
+ oAuth2AuthorizationCode.check,
211
+ oAuth2AuthorizationCode.create,
209
212
  oAuth2RefreshToken.check,
210
213
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
211
214
  authentication.check.mockResolvedValueOnce({
212
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
213
- scope: 'user,oauth',
214
- userId: '2',
215
+ clientId: 'the_client_id',
216
+ scopes: ['user', 'oauth'],
217
+ userId: 'auth_user_id',
215
218
  });
216
- checkApplication.mockResolvedValueOnce({
217
- type: 'code',
218
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
219
- scope: 'user,oauth',
220
- redirectURI: 'http://redirect.example.com/yolo',
219
+ readClientGrants.mockResolvedValueOnce({
220
+ allowedGrantTypes: ['authorization_code', 'password'],
221
+ allowedScopes: ['user', 'oauth'],
222
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
223
+ isPublicClient: false,
224
+ authenticationData: {
225
+ clientId: 'the_client_id',
226
+ scopes: ['user', 'oauth'],
227
+ userId: 'a_user_id',
228
+ },
221
229
  });
222
230
  oAuth2Password.check.mockResolvedValueOnce({
223
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
224
- scope: 'user,auth',
225
- userId: '1',
231
+ clientId: 'the_client_id',
232
+ scopes: ['user', 'oauth'],
233
+ userId: 'pwd_user_id',
226
234
  });
227
235
  oAuth2AccessToken.create.mockResolvedValueOnce({
228
236
  token: 'an_access_token',
@@ -242,60 +250,237 @@ describe('OAuth2 server', () => {
242
250
  grant_type: 'password',
243
251
  username: 'me@example.com',
244
252
  password: 'udelawli',
245
- scope: 'user',
253
+ scope: 'user invalid_scope',
246
254
  },
247
255
  validateStatus: () => true,
248
256
  });
249
257
  expect({
250
- status,
251
- headers: {
252
- ...headers,
253
- // Erasing the Date header that may be added by Axios :/
254
- date: undefined,
255
- etag: undefined,
256
- 'last-modified': undefined,
257
- server: undefined,
258
- connection: undefined,
259
- 'keep-alive': undefined,
260
- },
261
- data,
258
+ response: {
259
+ status,
260
+ headers: {
261
+ ...headers,
262
+ // Erasing the Date header that may be added by Axios :/
263
+ date: undefined,
264
+ etag: undefined,
265
+ 'last-modified': undefined,
266
+ server: undefined,
267
+ connection: undefined,
268
+ 'keep-alive': undefined,
269
+ },
270
+ data,
271
+ },
272
+ readClientGrantsCalls: readClientGrants.mock.calls,
273
+ authenticationCheckCalls: authentication.check.mock.calls,
274
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
275
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
276
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
277
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
278
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
279
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
280
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
262
281
  }).toMatchInlineSnapshot(`
263
282
  {
264
- "data": {
265
- "access_token": "an_access_token",
266
- "expiration_date": "2010-03-07T00:00:00.000Z",
267
- "expires_in": 86400,
268
- "refresh_token": "a_refresh_token",
269
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
270
- "refresh_token_expires_in": 5364748800,
271
- "token_type": "bearer",
283
+ "authenticationCheckCalls": [
284
+ [
285
+ "basic",
286
+ {
287
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
288
+ "password": "open_sesame",
289
+ "username": "ali",
290
+ },
291
+ ],
292
+ ],
293
+ "oAuth2AccessTokenCheckCalls": [],
294
+ "oAuth2AccessTokenCreateCalls": [
295
+ [
296
+ {
297
+ "clientId": "the_client_id",
298
+ "scopes": [
299
+ "user",
300
+ ],
301
+ "userId": "pwd_user_id",
302
+ },
303
+ ],
304
+ ],
305
+ "oAuth2AuthorizationCodeCheckCalls": [],
306
+ "oAuth2AuthorizationCodeCreateCalls": [],
307
+ "oAuth2PasswordCheckCalls": [
308
+ [
309
+ {
310
+ "clientId": "the_client_id",
311
+ "scopes": [
312
+ "user",
313
+ "oauth",
314
+ ],
315
+ "userId": "auth_user_id",
316
+ },
317
+ "me@example.com",
318
+ "udelawli",
319
+ ],
320
+ ],
321
+ "oAuth2RefreshTokenCheckCalls": [],
322
+ "oAuth2RefreshTokenCreateCalls": [
323
+ [
324
+ {
325
+ "clientId": "the_client_id",
326
+ "scopes": [
327
+ "user",
328
+ ],
329
+ "userId": "pwd_user_id",
330
+ },
331
+ ],
332
+ ],
333
+ "readClientGrantsCalls": [
334
+ [
335
+ "the_client_id",
336
+ ],
337
+ ],
338
+ "response": {
339
+ "data": {
340
+ "access_token": "an_access_token",
341
+ "expiration_date": "2010-03-07T00:00:00.000Z",
342
+ "expires_in": 86400,
343
+ "refresh_token": "a_refresh_token",
344
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
345
+ "refresh_token_expires_in": 5364748800,
346
+ "scope": "user",
347
+ "token_type": "bearer",
348
+ },
349
+ "headers": {
350
+ "cache-control": "no-store",
351
+ "connection": undefined,
352
+ "content-type": "application/json",
353
+ "date": undefined,
354
+ "etag": undefined,
355
+ "keep-alive": undefined,
356
+ "last-modified": undefined,
357
+ "pragma": "no-cache",
358
+ "server": undefined,
359
+ "transaction-id": "0",
360
+ "transfer-encoding": "chunked",
361
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
362
+ },
363
+ "status": 200,
272
364
  },
273
- "headers": {
274
- "connection": undefined,
275
- "content-type": "application/json",
276
- "date": undefined,
277
- "etag": undefined,
278
- "keep-alive": undefined,
279
- "last-modified": undefined,
280
- "server": undefined,
281
- "transaction-id": "0",
282
- "transfer-encoding": "chunked",
283
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
284
- },
285
- "status": 200,
286
365
  }
287
366
  `);
367
+ });
368
+ test('should fail with excluded clients', async () => {
369
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
370
+ [
371
+ oAuth2AccessToken.check,
372
+ oAuth2RefreshToken.check,
373
+ oAuth2AuthorizationCode.check,
374
+ oAuth2AuthorizationCode.create,
375
+ oAuth2RefreshToken.check,
376
+ oAuth2Password.check,
377
+ oAuth2AccessToken.create,
378
+ oAuth2RefreshToken.create,
379
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
380
+ authentication.check.mockResolvedValueOnce({
381
+ clientId: 'the_client_id',
382
+ scopes: ['user', 'oauth'],
383
+ userId: 'auth_user_id',
384
+ });
385
+ readClientGrants.mockResolvedValueOnce({
386
+ allowedGrantTypes: ['authorization_code'],
387
+ allowedScopes: ['user', 'oauth'],
388
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
389
+ isPublicClient: false,
390
+ authenticationData: {
391
+ clientId: 'the_client_id',
392
+ scopes: ['user', 'oauth'],
393
+ userId: 'a_user_id',
394
+ },
395
+ });
396
+ const { status, headers, data } = await axios({
397
+ method: 'post',
398
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
399
+ headers: {
400
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
401
+ },
402
+ data: {
403
+ grant_type: 'password',
404
+ username: 'me@example.com',
405
+ password: 'udelawli',
406
+ scope: 'user',
407
+ },
408
+ validateStatus: () => true,
409
+ });
288
410
  expect({
289
- checkApplicationCalls: checkApplication.mock.calls,
411
+ response: {
412
+ status,
413
+ headers: {
414
+ ...headers,
415
+ // Erasing the Date header that may be added by Axios :/
416
+ date: undefined,
417
+ etag: undefined,
418
+ 'last-modified': undefined,
419
+ server: undefined,
420
+ connection: undefined,
421
+ 'keep-alive': undefined,
422
+ },
423
+ data,
424
+ },
425
+ readClientGrantsCalls: readClientGrants.mock.calls,
290
426
  authenticationCheckCalls: authentication.check.mock.calls,
291
427
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
292
428
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
293
429
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
294
430
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
295
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
296
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
431
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
432
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
297
433
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
298
- }).toMatchSnapshot();
434
+ }).toMatchInlineSnapshot(`
435
+ {
436
+ "authenticationCheckCalls": [
437
+ [
438
+ "basic",
439
+ {
440
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
441
+ "password": "open_sesame",
442
+ "username": "ali",
443
+ },
444
+ ],
445
+ ],
446
+ "oAuth2AccessTokenCheckCalls": [],
447
+ "oAuth2AccessTokenCreateCalls": [],
448
+ "oAuth2AuthorizationCodeCheckCalls": [],
449
+ "oAuth2AuthorizationCodeCreateCalls": [],
450
+ "oAuth2PasswordCheckCalls": [],
451
+ "oAuth2RefreshTokenCheckCalls": [],
452
+ "oAuth2RefreshTokenCreateCalls": [],
453
+ "readClientGrantsCalls": [
454
+ [
455
+ "the_client_id",
456
+ ],
457
+ ],
458
+ "response": {
459
+ "data": {
460
+ "error": "unauthorized_client",
461
+ "error_debug_data": {
462
+ "guruMeditation": "1",
463
+ },
464
+ "error_description": "This grant type is not supported (password).",
465
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED+whook+error+code",
466
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
467
+ },
468
+ "headers": {
469
+ "cache-control": "private",
470
+ "connection": undefined,
471
+ "content-type": "text/plain",
472
+ "date": undefined,
473
+ "etag": undefined,
474
+ "keep-alive": undefined,
475
+ "last-modified": undefined,
476
+ "server": undefined,
477
+ "transaction-id": "1",
478
+ "transfer-encoding": "chunked",
479
+ },
480
+ "status": 400,
481
+ },
482
+ }
483
+ `);
299
484
  });
300
485
  });
301
486
  describe('with the refresh token flow', () => {
@@ -303,25 +488,30 @@ describe('OAuth2 server', () => {
303
488
  time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
304
489
  [
305
490
  oAuth2AccessToken.check,
306
- oAuth2Code.check,
307
- oAuth2Code.create,
491
+ oAuth2AuthorizationCode.check,
492
+ oAuth2AuthorizationCode.create,
308
493
  oAuth2Password.check,
309
494
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
310
495
  authentication.check.mockResolvedValueOnce({
311
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
312
- scope: 'user,oauth',
313
- userId: '2',
496
+ clientId: 'the_client_id',
497
+ scopes: ['user', 'oauth'],
498
+ userId: 'auth_user_id',
314
499
  });
315
- checkApplication.mockResolvedValueOnce({
316
- type: 'code',
317
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
318
- scope: 'user,oauth',
319
- redirectURI: 'http://redirect.example.com/yolo',
500
+ readClientGrants.mockResolvedValueOnce({
501
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
502
+ allowedScopes: ['user', 'oauth'],
503
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
504
+ isPublicClient: false,
505
+ authenticationData: {
506
+ clientId: 'the_client_id',
507
+ scopes: ['user', 'oauth'],
508
+ userId: 'a_user_id',
509
+ },
320
510
  });
321
511
  oAuth2RefreshToken.check.mockResolvedValueOnce({
322
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
323
- scope: 'user,auth',
324
- userId: '1',
512
+ clientId: 'the_client_id',
513
+ scopes: ['user', 'oauth'],
514
+ userId: 'a_user_id',
325
515
  });
326
516
  oAuth2AccessToken.create.mockResolvedValueOnce({
327
517
  token: 'an_access_token',
@@ -345,55 +535,348 @@ describe('OAuth2 server', () => {
345
535
  validateStatus: () => true,
346
536
  });
347
537
  expect({
348
- status,
349
- headers: {
350
- ...headers,
351
- // Erasing the Date header that may be added by Axios :/
352
- date: undefined,
353
- etag: undefined,
354
- 'last-modified': undefined,
355
- server: undefined,
356
- connection: undefined,
357
- 'keep-alive': undefined,
358
- },
359
- data,
538
+ response: {
539
+ status,
540
+ headers: {
541
+ ...headers,
542
+ // Erasing the Date header that may be added by Axios :/
543
+ date: undefined,
544
+ etag: undefined,
545
+ 'last-modified': undefined,
546
+ server: undefined,
547
+ connection: undefined,
548
+ 'keep-alive': undefined,
549
+ },
550
+ data,
551
+ },
552
+ readClientGrantsCalls: readClientGrants.mock.calls,
553
+ authenticationCheckCalls: authentication.check.mock.calls,
554
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
555
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
556
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
557
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
558
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
559
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
560
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
360
561
  }).toMatchInlineSnapshot(`
361
562
  {
362
- "data": {
363
- "access_token": "an_access_token",
364
- "expiration_date": "2010-03-07T00:00:00.000Z",
365
- "expires_in": 86400,
366
- "refresh_token": "a_refresh_token",
367
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
368
- "refresh_token_expires_in": 5364748800,
369
- "token_type": "bearer",
563
+ "authenticationCheckCalls": [
564
+ [
565
+ "basic",
566
+ {
567
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
568
+ "password": "open_sesame",
569
+ "username": "ali",
570
+ },
571
+ ],
572
+ ],
573
+ "oAuth2AccessTokenCheckCalls": [],
574
+ "oAuth2AccessTokenCreateCalls": [
575
+ [
576
+ {
577
+ "clientId": "the_client_id",
578
+ "scopes": [
579
+ "user",
580
+ ],
581
+ "userId": "a_user_id",
582
+ },
583
+ ],
584
+ ],
585
+ "oAuth2AuthorizationCodeCheckCalls": [],
586
+ "oAuth2AuthorizationCodeCreateCalls": [],
587
+ "oAuth2PasswordCheckCalls": [],
588
+ "oAuth2RefreshTokenCheckCalls": [
589
+ [
590
+ "a_refresh_token",
591
+ ],
592
+ ],
593
+ "oAuth2RefreshTokenCreateCalls": [
594
+ [
595
+ {
596
+ "clientId": "the_client_id",
597
+ "scopes": [
598
+ "user",
599
+ ],
600
+ "userId": "a_user_id",
601
+ },
602
+ ],
603
+ ],
604
+ "readClientGrantsCalls": [
605
+ [
606
+ "the_client_id",
607
+ ],
608
+ ],
609
+ "response": {
610
+ "data": {
611
+ "access_token": "an_access_token",
612
+ "expiration_date": "2010-03-07T00:00:00.000Z",
613
+ "expires_in": 86400,
614
+ "refresh_token": "a_refresh_token",
615
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
616
+ "refresh_token_expires_in": 5364748800,
617
+ "scope": "user",
618
+ "token_type": "bearer",
619
+ },
620
+ "headers": {
621
+ "cache-control": "no-store",
622
+ "connection": undefined,
623
+ "content-type": "application/json",
624
+ "date": undefined,
625
+ "etag": undefined,
626
+ "keep-alive": undefined,
627
+ "last-modified": undefined,
628
+ "pragma": "no-cache",
629
+ "server": undefined,
630
+ "transaction-id": "2",
631
+ "transfer-encoding": "chunked",
632
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
633
+ },
634
+ "status": 200,
370
635
  },
371
- "headers": {
372
- "connection": undefined,
373
- "content-type": "application/json",
374
- "date": undefined,
375
- "etag": undefined,
376
- "keep-alive": undefined,
377
- "last-modified": undefined,
378
- "server": undefined,
379
- "transaction-id": "1",
380
- "transfer-encoding": "chunked",
381
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
636
+ }
637
+ `);
638
+ });
639
+ test('should fail with excluded apps', async () => {
640
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
641
+ [
642
+ oAuth2AccessToken.check,
643
+ oAuth2AuthorizationCode.check,
644
+ oAuth2AuthorizationCode.create,
645
+ oAuth2Password.check,
646
+ oAuth2AccessToken.create,
647
+ oAuth2RefreshToken.create,
648
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
649
+ authentication.check.mockResolvedValueOnce({
650
+ clientId: 'the_client_id',
651
+ scopes: ['user', 'oauth'],
652
+ userId: 'auth_user_id',
653
+ });
654
+ readClientGrants.mockResolvedValueOnce({
655
+ allowedGrantTypes: ['authorization_code'],
656
+ allowedScopes: ['user', 'oauth'],
657
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
658
+ isPublicClient: false,
659
+ authenticationData: {
660
+ clientId: 'the_client_id',
661
+ scopes: ['user', 'oauth'],
662
+ userId: 'a_user_id',
663
+ },
664
+ });
665
+ oAuth2RefreshToken.check.mockResolvedValueOnce({
666
+ clientId: 'the_client_id',
667
+ scopes: ['user', 'oauth'],
668
+ userId: 'refresh_user_id',
669
+ });
670
+ const { status, headers, data } = await axios({
671
+ method: 'post',
672
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
673
+ headers: {
674
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
675
+ },
676
+ data: {
677
+ grant_type: 'refresh_token',
678
+ refresh_token: 'a_refresh_token',
679
+ scope: 'user',
680
+ },
681
+ validateStatus: () => true,
682
+ });
683
+ expect({
684
+ response: {
685
+ status,
686
+ headers: {
687
+ ...headers,
688
+ // Erasing the Date header that may be added by Axios :/
689
+ date: undefined,
690
+ etag: undefined,
691
+ 'last-modified': undefined,
692
+ server: undefined,
693
+ connection: undefined,
694
+ 'keep-alive': undefined,
695
+ },
696
+ data,
697
+ },
698
+ readClientGrantsCalls: readClientGrants.mock.calls,
699
+ authenticationCheckCalls: authentication.check.mock.calls,
700
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
701
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
702
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
703
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
704
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
705
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
706
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
707
+ }).toMatchInlineSnapshot(`
708
+ {
709
+ "authenticationCheckCalls": [
710
+ [
711
+ "basic",
712
+ {
713
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
714
+ "password": "open_sesame",
715
+ "username": "ali",
716
+ },
717
+ ],
718
+ ],
719
+ "oAuth2AccessTokenCheckCalls": [],
720
+ "oAuth2AccessTokenCreateCalls": [],
721
+ "oAuth2AuthorizationCodeCheckCalls": [],
722
+ "oAuth2AuthorizationCodeCreateCalls": [],
723
+ "oAuth2PasswordCheckCalls": [],
724
+ "oAuth2RefreshTokenCheckCalls": [
725
+ [
726
+ "a_refresh_token",
727
+ ],
728
+ ],
729
+ "oAuth2RefreshTokenCreateCalls": [],
730
+ "readClientGrantsCalls": [
731
+ [
732
+ "the_client_id",
733
+ ],
734
+ ],
735
+ "response": {
736
+ "data": {
737
+ "error": "unauthorized_client",
738
+ "error_debug_data": {
739
+ "guruMeditation": "3",
740
+ },
741
+ "error_description": "This grant type is not supported (refresh_token).",
742
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED+whook+error+code",
743
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
744
+ },
745
+ "headers": {
746
+ "cache-control": "private",
747
+ "connection": undefined,
748
+ "content-type": "text/plain",
749
+ "date": undefined,
750
+ "etag": undefined,
751
+ "keep-alive": undefined,
752
+ "last-modified": undefined,
753
+ "server": undefined,
754
+ "transaction-id": "3",
755
+ "transfer-encoding": "chunked",
756
+ },
757
+ "status": 400,
382
758
  },
383
- "status": 200,
384
759
  }
385
760
  `);
761
+ });
762
+ test('should fail with application id mismatch', async () => {
763
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
764
+ [
765
+ oAuth2AccessToken.check,
766
+ oAuth2AuthorizationCode.check,
767
+ oAuth2AuthorizationCode.create,
768
+ oAuth2Password.check,
769
+ oAuth2AccessToken.create,
770
+ oAuth2RefreshToken.create,
771
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
772
+ authentication.check.mockResolvedValueOnce({
773
+ clientId: 'another_client_id',
774
+ scopes: ['user', 'oauth'],
775
+ userId: 'auth_user_id',
776
+ });
777
+ readClientGrants.mockResolvedValueOnce({
778
+ allowedGrantTypes: ['authorization_code'],
779
+ allowedScopes: ['user', 'oauth'],
780
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
781
+ isPublicClient: false,
782
+ authenticationData: {
783
+ clientId: 'the_client_id',
784
+ scopes: ['user', 'oauth'],
785
+ userId: 'a_user_id',
786
+ },
787
+ });
788
+ oAuth2RefreshToken.check.mockResolvedValueOnce({
789
+ clientId: 'the_client_id',
790
+ scopes: ['user', 'oauth'],
791
+ userId: 'refresh_user_id',
792
+ });
793
+ const { status, headers, data } = await axios({
794
+ method: 'post',
795
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
796
+ headers: {
797
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
798
+ },
799
+ data: {
800
+ grant_type: 'refresh_token',
801
+ refresh_token: 'a_refresh_token',
802
+ scope: 'user',
803
+ },
804
+ validateStatus: () => true,
805
+ });
386
806
  expect({
387
- checkApplicationCalls: checkApplication.mock.calls,
807
+ response: {
808
+ status,
809
+ headers: {
810
+ ...headers,
811
+ // Erasing the Date header that may be added by Axios :/
812
+ date: undefined,
813
+ etag: undefined,
814
+ 'last-modified': undefined,
815
+ server: undefined,
816
+ connection: undefined,
817
+ 'keep-alive': undefined,
818
+ },
819
+ data,
820
+ },
821
+ readClientGrantsCalls: readClientGrants.mock.calls,
388
822
  authenticationCheckCalls: authentication.check.mock.calls,
389
823
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
390
824
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
391
825
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
392
826
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
393
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
394
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
827
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
828
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
395
829
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
396
- }).toMatchSnapshot();
830
+ }).toMatchInlineSnapshot(`
831
+ {
832
+ "authenticationCheckCalls": [
833
+ [
834
+ "basic",
835
+ {
836
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
837
+ "password": "open_sesame",
838
+ "username": "ali",
839
+ },
840
+ ],
841
+ ],
842
+ "oAuth2AccessTokenCheckCalls": [],
843
+ "oAuth2AccessTokenCreateCalls": [],
844
+ "oAuth2AuthorizationCodeCheckCalls": [],
845
+ "oAuth2AuthorizationCodeCreateCalls": [],
846
+ "oAuth2PasswordCheckCalls": [],
847
+ "oAuth2RefreshTokenCheckCalls": [
848
+ [
849
+ "a_refresh_token",
850
+ ],
851
+ ],
852
+ "oAuth2RefreshTokenCreateCalls": [],
853
+ "readClientGrantsCalls": [],
854
+ "response": {
855
+ "data": {
856
+ "error": "invalid_request",
857
+ "error_debug_data": {
858
+ "guruMeditation": "4",
859
+ },
860
+ "error_description": "The client used is not matching the request.",
861
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_CLIENT_MISMATCH+whook+error+code",
862
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_CLIENT_MISMATCH",
863
+ },
864
+ "headers": {
865
+ "cache-control": "private",
866
+ "connection": undefined,
867
+ "content-type": "text/plain",
868
+ "date": undefined,
869
+ "etag": undefined,
870
+ "keep-alive": undefined,
871
+ "last-modified": undefined,
872
+ "server": undefined,
873
+ "transaction-id": "4",
874
+ "transfer-encoding": "chunked",
875
+ },
876
+ "status": 400,
877
+ },
878
+ }
879
+ `);
397
880
  });
398
881
  });
399
882
  describe('with the client credentials flow', () => {
@@ -402,20 +885,25 @@ describe('OAuth2 server', () => {
402
885
  [
403
886
  oAuth2AccessToken.check,
404
887
  oAuth2RefreshToken.check,
405
- oAuth2Code.check,
406
- oAuth2Code.create,
888
+ oAuth2AuthorizationCode.check,
889
+ oAuth2AuthorizationCode.create,
407
890
  oAuth2Password.check,
408
891
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
409
892
  authentication.check.mockResolvedValueOnce({
410
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
411
- scope: 'user,oauth',
412
- userId: '2',
893
+ clientId: 'the_client_id',
894
+ scopes: ['user', 'oauth'],
895
+ userId: 'auth_user_id',
413
896
  });
414
- checkApplication.mockResolvedValueOnce({
415
- type: 'code',
416
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
417
- scope: 'user,oauth',
418
- redirectURI: 'http://redirect.example.com/yolo',
897
+ readClientGrants.mockResolvedValueOnce({
898
+ allowedGrantTypes: ['authorization_code', 'client_credentials'],
899
+ allowedScopes: ['user', 'oauth'],
900
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
901
+ isPublicClient: false,
902
+ authenticationData: {
903
+ clientId: 'the_client_id',
904
+ scopes: ['user', 'oauth'],
905
+ userId: 'a_user_id',
906
+ },
419
907
  });
420
908
  oAuth2AccessToken.create.mockResolvedValueOnce({
421
909
  token: 'an_access_token',
@@ -438,55 +926,203 @@ describe('OAuth2 server', () => {
438
926
  validateStatus: () => true,
439
927
  });
440
928
  expect({
441
- status,
442
- headers: {
443
- ...headers,
444
- // Erasing the Date header that may be added by Axios :/
445
- date: undefined,
446
- etag: undefined,
447
- 'last-modified': undefined,
448
- server: undefined,
449
- connection: undefined,
450
- 'keep-alive': undefined,
451
- },
452
- data,
929
+ response: {
930
+ status,
931
+ headers: {
932
+ ...headers,
933
+ // Erasing the Date header that may be added by Axios :/
934
+ date: undefined,
935
+ etag: undefined,
936
+ 'last-modified': undefined,
937
+ server: undefined,
938
+ connection: undefined,
939
+ 'keep-alive': undefined,
940
+ },
941
+ data,
942
+ },
943
+ readClientGrantsCalls: readClientGrants.mock.calls,
944
+ authenticationCheckCalls: authentication.check.mock.calls,
945
+ oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
946
+ oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
947
+ oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
948
+ oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
949
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
950
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
951
+ oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
453
952
  }).toMatchInlineSnapshot(`
454
953
  {
455
- "data": {
456
- "access_token": "an_access_token",
457
- "expiration_date": "2010-03-07T00:00:00.000Z",
458
- "expires_in": 86400,
459
- "refresh_token": "a_refresh_token",
460
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
461
- "refresh_token_expires_in": 5364748800,
462
- "token_type": "bearer",
954
+ "authenticationCheckCalls": [
955
+ [
956
+ "basic",
957
+ {
958
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
959
+ "password": "open_sesame",
960
+ "username": "ali",
961
+ },
962
+ ],
963
+ ],
964
+ "oAuth2AccessTokenCheckCalls": [],
965
+ "oAuth2AccessTokenCreateCalls": [
966
+ [
967
+ {
968
+ "clientId": "the_client_id",
969
+ "scopes": [
970
+ "user",
971
+ ],
972
+ "userId": "auth_user_id",
973
+ },
974
+ ],
975
+ ],
976
+ "oAuth2AuthorizationCodeCheckCalls": [],
977
+ "oAuth2AuthorizationCodeCreateCalls": [],
978
+ "oAuth2PasswordCheckCalls": [],
979
+ "oAuth2RefreshTokenCheckCalls": [],
980
+ "oAuth2RefreshTokenCreateCalls": [],
981
+ "readClientGrantsCalls": [
982
+ [
983
+ "the_client_id",
984
+ ],
985
+ ],
986
+ "response": {
987
+ "data": {
988
+ "access_token": "an_access_token",
989
+ "expiration_date": "2010-03-07T00:00:00.000Z",
990
+ "expires_in": 86400,
991
+ "scope": "user",
992
+ "token_type": "bearer",
993
+ },
994
+ "headers": {
995
+ "cache-control": "no-store",
996
+ "connection": undefined,
997
+ "content-type": "application/json",
998
+ "date": undefined,
999
+ "etag": undefined,
1000
+ "keep-alive": undefined,
1001
+ "last-modified": undefined,
1002
+ "pragma": "no-cache",
1003
+ "server": undefined,
1004
+ "transaction-id": "5",
1005
+ "transfer-encoding": "chunked",
1006
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1007
+ },
1008
+ "status": 200,
463
1009
  },
464
- "headers": {
465
- "connection": undefined,
466
- "content-type": "application/json",
467
- "date": undefined,
468
- "etag": undefined,
469
- "keep-alive": undefined,
470
- "last-modified": undefined,
471
- "server": undefined,
472
- "transaction-id": "2",
473
- "transfer-encoding": "chunked",
474
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
475
- },
476
- "status": 200,
477
1010
  }
478
1011
  `);
1012
+ });
1013
+ test('should fail with excluded apps', async () => {
1014
+ time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
1015
+ [
1016
+ oAuth2AccessToken.check,
1017
+ oAuth2RefreshToken.check,
1018
+ oAuth2AuthorizationCode.check,
1019
+ oAuth2AuthorizationCode.create,
1020
+ oAuth2Password.check,
1021
+ oAuth2AccessToken.create,
1022
+ oAuth2RefreshToken.create,
1023
+ ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
1024
+ authentication.check.mockResolvedValueOnce({
1025
+ clientId: 'the_client_id',
1026
+ scopes: ['user', 'oauth'],
1027
+ userId: 'auth_user_id',
1028
+ });
1029
+ readClientGrants.mockResolvedValueOnce({
1030
+ allowedGrantTypes: ['authorization_code'],
1031
+ allowedScopes: ['user', 'oauth'],
1032
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1033
+ isPublicClient: false,
1034
+ authenticationData: {
1035
+ clientId: 'the_client_id',
1036
+ scopes: ['user', 'oauth'],
1037
+ userId: 'a_user_id',
1038
+ },
1039
+ });
1040
+ const { status, headers, data } = await axios({
1041
+ method: 'post',
1042
+ url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
1043
+ headers: {
1044
+ authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
1045
+ },
1046
+ data: {
1047
+ grant_type: 'client_credentials',
1048
+ scope: 'user',
1049
+ },
1050
+ validateStatus: () => true,
1051
+ });
479
1052
  expect({
480
- checkApplicationCalls: checkApplication.mock.calls,
1053
+ response: {
1054
+ status,
1055
+ headers: {
1056
+ ...headers,
1057
+ // Erasing the Date header that may be added by Axios :/
1058
+ date: undefined,
1059
+ etag: undefined,
1060
+ 'last-modified': undefined,
1061
+ server: undefined,
1062
+ connection: undefined,
1063
+ 'keep-alive': undefined,
1064
+ },
1065
+ data,
1066
+ },
1067
+ readClientGrantsCalls: readClientGrants.mock.calls,
481
1068
  authenticationCheckCalls: authentication.check.mock.calls,
482
1069
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
483
1070
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
484
1071
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
485
1072
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
486
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
487
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1073
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
1074
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
488
1075
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
489
- }).toMatchSnapshot();
1076
+ }).toMatchInlineSnapshot(`
1077
+ {
1078
+ "authenticationCheckCalls": [
1079
+ [
1080
+ "basic",
1081
+ {
1082
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
1083
+ "password": "open_sesame",
1084
+ "username": "ali",
1085
+ },
1086
+ ],
1087
+ ],
1088
+ "oAuth2AccessTokenCheckCalls": [],
1089
+ "oAuth2AccessTokenCreateCalls": [],
1090
+ "oAuth2AuthorizationCodeCheckCalls": [],
1091
+ "oAuth2AuthorizationCodeCreateCalls": [],
1092
+ "oAuth2PasswordCheckCalls": [],
1093
+ "oAuth2RefreshTokenCheckCalls": [],
1094
+ "oAuth2RefreshTokenCreateCalls": [],
1095
+ "readClientGrantsCalls": [
1096
+ [
1097
+ "the_client_id",
1098
+ ],
1099
+ ],
1100
+ "response": {
1101
+ "data": {
1102
+ "error": "unauthorized_client",
1103
+ "error_debug_data": {
1104
+ "guruMeditation": "6",
1105
+ },
1106
+ "error_description": "This grant type is not supported (client_credentials).",
1107
+ "error_help_uri": "https://stackoverflow.com/questions/ask?tags=whook&title=How+to+debug+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED+whook+error+code",
1108
+ "error_uri": "https://stackoverflow.com/search?q=%5Bwhook%5D+E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
1109
+ },
1110
+ "headers": {
1111
+ "cache-control": "private",
1112
+ "connection": undefined,
1113
+ "content-type": "text/plain",
1114
+ "date": undefined,
1115
+ "etag": undefined,
1116
+ "keep-alive": undefined,
1117
+ "last-modified": undefined,
1118
+ "server": undefined,
1119
+ "transaction-id": "6",
1120
+ "transfer-encoding": "chunked",
1121
+ },
1122
+ "status": 400,
1123
+ },
1124
+ }
1125
+ `);
490
1126
  });
491
1127
  });
492
1128
  describe('with the code flow', () => {
@@ -498,23 +1134,30 @@ describe('OAuth2 server', () => {
498
1134
  oAuth2AccessToken.create,
499
1135
  oAuth2RefreshToken.check,
500
1136
  oAuth2RefreshToken.create,
501
- oAuth2Code.check,
502
- oAuth2Code.create,
1137
+ oAuth2AuthorizationCode.check,
1138
+ oAuth2AuthorizationCode.create,
503
1139
  oAuth2Password.check,
504
1140
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
505
- checkApplication.mockResolvedValueOnce({
506
- type: 'code',
507
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
508
- scope: 'user,oauth',
509
- redirectURI: 'https://redirect.example.com/oauth2/callback?a_param=a_param_value',
1141
+ readClientGrants.mockResolvedValueOnce({
1142
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
1143
+ allowedScopes: ['user', 'oauth'],
1144
+ allowedRedirectURIS: [
1145
+ 'https://redirect.example.com/oauth2/callback?a_param=a_param_value',
1146
+ ],
1147
+ isPublicClient: false,
1148
+ authenticationData: {
1149
+ clientId: 'the_client_id',
1150
+ scopes: ['user', 'oauth'],
1151
+ userId: 'a_user_id',
1152
+ },
510
1153
  });
511
1154
  const { status, headers, data } = await axios({
512
1155
  method: 'get',
513
1156
  url: `http://${HOST}:${PORT}${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`,
514
1157
  params: {
515
1158
  response_type: 'code',
516
- client_id: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
517
- redirect_uri: 'https://example.com/oauth2/callback?a_param=a_param_value',
1159
+ client_id: 'the_client_id',
1160
+ redirect_uri: 'https://redirect.example.com/oauth2/callback?a_param=a_param_value',
518
1161
  scope: 'user',
519
1162
  state: 'xyz',
520
1163
  },
@@ -522,46 +1165,61 @@ describe('OAuth2 server', () => {
522
1165
  validateStatus: () => true,
523
1166
  });
524
1167
  expect({
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
- }).toMatchInlineSnapshot(`
538
- {
539
- "data": "",
540
- "headers": {
541
- "connection": undefined,
542
- "date": undefined,
543
- "etag": undefined,
544
- "keep-alive": undefined,
545
- "last-modified": undefined,
546
- "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",
547
- "server": undefined,
548
- "transaction-id": "3",
549
- "transfer-encoding": "chunked",
550
- },
551
- "status": 302,
552
- }
553
- `);
554
- expect({
555
- checkApplicationCalls: checkApplication.mock.calls,
1168
+ response: {
1169
+ status,
1170
+ headers: {
1171
+ ...headers,
1172
+ // Erasing the Date header that may be added by Axios :/
1173
+ date: undefined,
1174
+ etag: undefined,
1175
+ 'last-modified': undefined,
1176
+ server: undefined,
1177
+ connection: undefined,
1178
+ 'keep-alive': undefined,
1179
+ },
1180
+ data,
1181
+ },
1182
+ readClientGrantsCalls: readClientGrants.mock.calls,
556
1183
  authenticationCheckCalls: authentication.check.mock.calls,
557
1184
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
558
1185
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
559
1186
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
560
1187
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
561
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
562
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1188
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
1189
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
563
1190
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
564
- }).toMatchSnapshot();
1191
+ }).toMatchInlineSnapshot(`
1192
+ {
1193
+ "authenticationCheckCalls": [],
1194
+ "oAuth2AccessTokenCheckCalls": [],
1195
+ "oAuth2AccessTokenCreateCalls": [],
1196
+ "oAuth2AuthorizationCodeCheckCalls": [],
1197
+ "oAuth2AuthorizationCodeCreateCalls": [],
1198
+ "oAuth2PasswordCheckCalls": [],
1199
+ "oAuth2RefreshTokenCheckCalls": [],
1200
+ "oAuth2RefreshTokenCreateCalls": [],
1201
+ "readClientGrantsCalls": [
1202
+ [
1203
+ "the_client_id",
1204
+ ],
1205
+ ],
1206
+ "response": {
1207
+ "data": "",
1208
+ "headers": {
1209
+ "connection": undefined,
1210
+ "date": undefined,
1211
+ "etag": undefined,
1212
+ "keep-alive": undefined,
1213
+ "last-modified": undefined,
1214
+ "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",
1215
+ "server": undefined,
1216
+ "transaction-id": "7",
1217
+ "transfer-encoding": "chunked",
1218
+ },
1219
+ "status": 302,
1220
+ },
1221
+ }
1222
+ `);
565
1223
  });
566
1224
  test('should redirect with a code', async () => {
567
1225
  time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
@@ -570,20 +1228,39 @@ describe('OAuth2 server', () => {
570
1228
  oAuth2AccessToken.create,
571
1229
  oAuth2RefreshToken.check,
572
1230
  oAuth2RefreshToken.create,
573
- oAuth2Code.check,
1231
+ oAuth2AuthorizationCode.check,
574
1232
  oAuth2Password.check,
575
1233
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
576
1234
  authentication.check.mockResolvedValueOnce({
577
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
578
- scope: 'user,oauth',
579
- userId: '2',
1235
+ clientId: 'the_root_client_id',
1236
+ scopes: ['user', 'oauth'],
1237
+ userId: 'auth_user_id',
1238
+ });
1239
+ oAuth2AuthorizationCode.create.mockResolvedValueOnce('a_code');
1240
+ readClientGrants.mockResolvedValueOnce({
1241
+ allowedGrantTypes: ['password'],
1242
+ allowedScopes: [],
1243
+ allowedRedirectURIS: [],
1244
+ isPublicClient: false,
1245
+ canAcknowledge: true,
1246
+ authenticationData: {
1247
+ clientId: 'the_root_client_id',
1248
+ scopes: [],
1249
+ userId: 'a_user_id',
1250
+ },
580
1251
  });
581
- oAuth2Code.create.mockResolvedValueOnce('a_code');
582
- checkApplication.mockResolvedValueOnce({
583
- type: 'code',
584
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
585
- scope: 'user,oauth',
586
- redirectURI: 'http://redirect.example.com/yolo',
1252
+ readClientGrants.mockResolvedValueOnce({
1253
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
1254
+ allowedScopes: ['user', 'oauth'],
1255
+ allowedRedirectURIS: [
1256
+ 'http://redirect.example.com/yolo?a_param=a_value',
1257
+ ],
1258
+ isPublicClient: false,
1259
+ authenticationData: {
1260
+ clientId: 'the_client_id',
1261
+ scopes: ['user', 'oauth'],
1262
+ userId: 'a_user_id',
1263
+ },
587
1264
  });
588
1265
  const { status, headers, data } = await axios({
589
1266
  method: 'post',
@@ -593,7 +1270,7 @@ describe('OAuth2 server', () => {
593
1270
  },
594
1271
  data: {
595
1272
  responseType: 'code',
596
- clientId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1273
+ clientId: 'the_client_id',
597
1274
  redirectURI: 'http://redirect.example.com/yolo?a_param=a_value',
598
1275
  scope: 'user',
599
1276
  state: 'xyz',
@@ -603,47 +1280,91 @@ describe('OAuth2 server', () => {
603
1280
  validateStatus: () => true,
604
1281
  });
605
1282
  expect({
606
- status,
607
- headers: {
608
- ...headers,
609
- // Erasing the Date header that may be added by Axios :/
610
- date: undefined,
611
- etag: undefined,
612
- 'last-modified': undefined,
613
- server: undefined,
614
- connection: undefined,
615
- 'keep-alive': undefined,
616
- },
617
- data,
618
- }).toMatchInlineSnapshot(`
619
- {
620
- "data": "",
621
- "headers": {
622
- "connection": undefined,
623
- "date": undefined,
624
- "etag": undefined,
625
- "keep-alive": undefined,
626
- "last-modified": undefined,
627
- "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&code=a_code",
628
- "server": undefined,
629
- "transaction-id": "4",
630
- "transfer-encoding": "chunked",
631
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
632
- },
633
- "status": 302,
634
- }
635
- `);
636
- expect({
637
- checkApplicationCalls: checkApplication.mock.calls,
1283
+ response: {
1284
+ status,
1285
+ headers: {
1286
+ ...headers,
1287
+ // Erasing the Date header that may be added by Axios :/
1288
+ date: undefined,
1289
+ etag: undefined,
1290
+ 'last-modified': undefined,
1291
+ server: undefined,
1292
+ connection: undefined,
1293
+ 'keep-alive': undefined,
1294
+ },
1295
+ data,
1296
+ },
1297
+ readClientGrantsCalls: readClientGrants.mock.calls,
638
1298
  authenticationCheckCalls: authentication.check.mock.calls,
639
1299
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
640
1300
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
641
1301
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
642
1302
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
643
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
644
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1303
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
1304
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
645
1305
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
646
- }).toMatchSnapshot();
1306
+ }).toMatchInlineSnapshot(`
1307
+ {
1308
+ "authenticationCheckCalls": [
1309
+ [
1310
+ "bearer",
1311
+ {
1312
+ "hash": "yolo",
1313
+ },
1314
+ ],
1315
+ ],
1316
+ "oAuth2AccessTokenCheckCalls": [],
1317
+ "oAuth2AccessTokenCreateCalls": [],
1318
+ "oAuth2AuthorizationCodeCheckCalls": [],
1319
+ "oAuth2AuthorizationCodeCreateCalls": [
1320
+ [
1321
+ {
1322
+ "clientId": "the_client_id",
1323
+ "scopes": [
1324
+ "user",
1325
+ ],
1326
+ "userId": "auth_user_id",
1327
+ },
1328
+ {
1329
+ "demandedRedirectURI": "http://redirect.example.com/yolo?a_param=a_value",
1330
+ "demandedScopes": [
1331
+ "user",
1332
+ ],
1333
+ "filteredScopes": [
1334
+ "user",
1335
+ ],
1336
+ },
1337
+ ],
1338
+ ],
1339
+ "oAuth2PasswordCheckCalls": [],
1340
+ "oAuth2RefreshTokenCheckCalls": [],
1341
+ "oAuth2RefreshTokenCreateCalls": [],
1342
+ "readClientGrantsCalls": [
1343
+ [
1344
+ "the_root_client_id",
1345
+ ],
1346
+ [
1347
+ "the_client_id",
1348
+ ],
1349
+ ],
1350
+ "response": {
1351
+ "data": "",
1352
+ "headers": {
1353
+ "connection": undefined,
1354
+ "date": undefined,
1355
+ "etag": undefined,
1356
+ "keep-alive": undefined,
1357
+ "last-modified": undefined,
1358
+ "location": "http://redirect.example.com/yolo?a_param=a_value&client_id=the_client_id&scope=user&state=xyz&code=a_code",
1359
+ "server": undefined,
1360
+ "transaction-id": "8",
1361
+ "transfer-encoding": "chunked",
1362
+ "x-authenticated": "{"clientId":"the_root_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1363
+ },
1364
+ "status": 201,
1365
+ },
1366
+ }
1367
+ `);
647
1368
  });
648
1369
  test('should produce new tokens', async () => {
649
1370
  time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
@@ -653,21 +1374,32 @@ describe('OAuth2 server', () => {
653
1374
  oAuth2Password.check,
654
1375
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
655
1376
  authentication.check.mockResolvedValueOnce({
656
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
657
- scope: 'user,oauth',
658
- userId: '2',
659
- });
660
- checkApplication.mockResolvedValueOnce({
661
- type: 'code',
662
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
663
- scope: 'user,oauth',
664
- redirectURI: 'http://redirect.example.com/yolo',
665
- });
666
- oAuth2Code.check.mockResolvedValueOnce({
667
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
668
- scope: 'user,auth',
669
- userId: '1',
670
- redirectURI: 'http://redirect.example.com/yolo',
1377
+ clientId: 'the_client_id',
1378
+ scopes: ['user', 'oauth'],
1379
+ userId: 'auth_user_id',
1380
+ });
1381
+ readClientGrants.mockResolvedValueOnce({
1382
+ allowedGrantTypes: ['authorization_code', 'refresh_token'],
1383
+ allowedScopes: ['user', 'oauth'],
1384
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1385
+ isPublicClient: false,
1386
+ authenticationData: {
1387
+ clientId: 'the_client_id',
1388
+ scopes: ['user', 'oauth'],
1389
+ userId: 'a_user_id',
1390
+ },
1391
+ });
1392
+ oAuth2AuthorizationCode.check.mockResolvedValueOnce({
1393
+ codeAuthenticationData: {
1394
+ clientId: 'the_client_id',
1395
+ scopes: ['user', 'oauth'],
1396
+ userId: 'a_user_id',
1397
+ },
1398
+ context: {
1399
+ demandedRedirectURI: 'http://redirect.example.com/yolo',
1400
+ demandedScopes: ['user'],
1401
+ filteredScopes: ['user'],
1402
+ },
671
1403
  });
672
1404
  oAuth2AccessToken.create.mockResolvedValueOnce({
673
1405
  token: 'an_access_token',
@@ -691,55 +1423,114 @@ describe('OAuth2 server', () => {
691
1423
  validateStatus: () => true,
692
1424
  });
693
1425
  expect({
694
- status,
695
- headers: {
696
- ...headers,
697
- // Erasing the Date header that may be added by Axios :/
698
- date: undefined,
699
- etag: undefined,
700
- 'last-modified': undefined,
701
- server: undefined,
702
- connection: undefined,
703
- 'keep-alive': undefined,
704
- },
705
- data,
706
- }).toMatchInlineSnapshot(`
707
- {
708
- "data": {
709
- "access_token": "an_access_token",
710
- "expiration_date": "2010-03-07T00:00:00.000Z",
711
- "expires_in": 86400,
712
- "refresh_token": "a_refresh_token",
713
- "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
714
- "refresh_token_expires_in": 5364748800,
715
- "token_type": "bearer",
716
- },
717
- "headers": {
718
- "connection": undefined,
719
- "content-type": "application/json",
720
- "date": undefined,
721
- "etag": undefined,
722
- "keep-alive": undefined,
723
- "last-modified": undefined,
724
- "server": undefined,
725
- "transaction-id": "5",
726
- "transfer-encoding": "chunked",
727
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
728
- },
729
- "status": 200,
730
- }
731
- `);
732
- expect({
733
- checkApplicationCalls: checkApplication.mock.calls,
1426
+ response: {
1427
+ status,
1428
+ headers: {
1429
+ ...headers,
1430
+ // Erasing the Date header that may be added by Axios :/
1431
+ date: undefined,
1432
+ etag: undefined,
1433
+ 'last-modified': undefined,
1434
+ server: undefined,
1435
+ connection: undefined,
1436
+ 'keep-alive': undefined,
1437
+ },
1438
+ data,
1439
+ },
1440
+ readClientGrantsCalls: readClientGrants.mock.calls,
734
1441
  authenticationCheckCalls: authentication.check.mock.calls,
735
1442
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
736
1443
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
737
1444
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
738
1445
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
739
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
740
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1446
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
1447
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
741
1448
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
742
- }).toMatchSnapshot();
1449
+ }).toMatchInlineSnapshot(`
1450
+ {
1451
+ "authenticationCheckCalls": [
1452
+ [
1453
+ "basic",
1454
+ {
1455
+ "hash": "YWxpOm9wZW5fc2VzYW1l",
1456
+ "password": "open_sesame",
1457
+ "username": "ali",
1458
+ },
1459
+ ],
1460
+ ],
1461
+ "oAuth2AccessTokenCheckCalls": [],
1462
+ "oAuth2AccessTokenCreateCalls": [
1463
+ [
1464
+ {
1465
+ "clientId": "the_client_id",
1466
+ "scopes": [
1467
+ "user",
1468
+ ],
1469
+ "userId": "a_user_id",
1470
+ },
1471
+ ],
1472
+ ],
1473
+ "oAuth2AuthorizationCodeCheckCalls": [
1474
+ [
1475
+ {
1476
+ "clientId": "the_client_id",
1477
+ "scopes": [
1478
+ "user",
1479
+ "oauth",
1480
+ ],
1481
+ "userId": "auth_user_id",
1482
+ },
1483
+ "a_grant_code",
1484
+ ],
1485
+ ],
1486
+ "oAuth2AuthorizationCodeCreateCalls": [],
1487
+ "oAuth2PasswordCheckCalls": [],
1488
+ "oAuth2RefreshTokenCheckCalls": [],
1489
+ "oAuth2RefreshTokenCreateCalls": [
1490
+ [
1491
+ {
1492
+ "clientId": "the_client_id",
1493
+ "scopes": [
1494
+ "user",
1495
+ ],
1496
+ "userId": "a_user_id",
1497
+ },
1498
+ ],
1499
+ ],
1500
+ "readClientGrantsCalls": [
1501
+ [
1502
+ "the_client_id",
1503
+ ],
1504
+ ],
1505
+ "response": {
1506
+ "data": {
1507
+ "access_token": "an_access_token",
1508
+ "expiration_date": "2010-03-07T00:00:00.000Z",
1509
+ "expires_in": 86400,
1510
+ "refresh_token": "a_refresh_token",
1511
+ "refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
1512
+ "refresh_token_expires_in": 5364748800,
1513
+ "scope": "user",
1514
+ "token_type": "bearer",
1515
+ },
1516
+ "headers": {
1517
+ "cache-control": "no-store",
1518
+ "connection": undefined,
1519
+ "content-type": "application/json",
1520
+ "date": undefined,
1521
+ "etag": undefined,
1522
+ "keep-alive": undefined,
1523
+ "last-modified": undefined,
1524
+ "pragma": "no-cache",
1525
+ "server": undefined,
1526
+ "transaction-id": "9",
1527
+ "transfer-encoding": "chunked",
1528
+ "x-authenticated": "{"clientId":"the_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1529
+ },
1530
+ "status": 200,
1531
+ },
1532
+ }
1533
+ `);
743
1534
  });
744
1535
  });
745
1536
  describe('with the implicit flow', () => {
@@ -751,22 +1542,27 @@ describe('OAuth2 server', () => {
751
1542
  oAuth2AccessToken.create,
752
1543
  oAuth2RefreshToken.check,
753
1544
  oAuth2RefreshToken.create,
754
- oAuth2Code.check,
755
- oAuth2Code.create,
1545
+ oAuth2AuthorizationCode.check,
1546
+ oAuth2AuthorizationCode.create,
756
1547
  oAuth2Password.check,
757
1548
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
758
- checkApplication.mockResolvedValueOnce({
759
- type: 'implicit',
760
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
761
- scope: 'user,oauth',
762
- redirectURI: 'http://redirect.example.com/yolo',
1549
+ readClientGrants.mockResolvedValueOnce({
1550
+ allowedGrantTypes: ['implicit'],
1551
+ allowedScopes: ['user', 'oauth'],
1552
+ allowedRedirectURIS: ['http://redirect.example.com/yolo'],
1553
+ isPublicClient: false,
1554
+ authenticationData: {
1555
+ clientId: 'the_client_id',
1556
+ scopes: ['user', 'oauth'],
1557
+ userId: 'a_user_id',
1558
+ },
763
1559
  });
764
1560
  const { status, headers, data } = await axios({
765
1561
  method: 'get',
766
1562
  url: `http://${HOST}:${PORT}${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`,
767
1563
  params: {
768
1564
  response_type: 'token',
769
- client_id: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1565
+ client_id: 'the_client_id',
770
1566
  redirect_uri: 'http://redirect.example.com/yolo',
771
1567
  scope: 'user',
772
1568
  state: 'xyz',
@@ -775,46 +1571,61 @@ describe('OAuth2 server', () => {
775
1571
  validateStatus: () => true,
776
1572
  });
777
1573
  expect({
778
- status,
779
- headers: {
780
- ...headers,
781
- // Erasing the Date header that may be added by Axios :/
782
- date: undefined,
783
- etag: undefined,
784
- 'last-modified': undefined,
785
- server: undefined,
786
- connection: undefined,
787
- 'keep-alive': undefined,
788
- },
789
- data,
790
- }).toMatchInlineSnapshot(`
791
- {
792
- "data": "",
793
- "headers": {
794
- "connection": undefined,
795
- "date": undefined,
796
- "etag": undefined,
797
- "keep-alive": undefined,
798
- "last-modified": undefined,
799
- "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",
800
- "server": undefined,
801
- "transaction-id": "6",
802
- "transfer-encoding": "chunked",
803
- },
804
- "status": 302,
805
- }
806
- `);
807
- expect({
808
- checkApplicationCalls: checkApplication.mock.calls,
1574
+ response: {
1575
+ status,
1576
+ headers: {
1577
+ ...headers,
1578
+ // Erasing the Date header that may be added by Axios :/
1579
+ date: undefined,
1580
+ etag: undefined,
1581
+ 'last-modified': undefined,
1582
+ server: undefined,
1583
+ connection: undefined,
1584
+ 'keep-alive': undefined,
1585
+ },
1586
+ data,
1587
+ },
1588
+ readClientGrantsCalls: readClientGrants.mock.calls,
809
1589
  authenticationCheckCalls: authentication.check.mock.calls,
810
1590
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
811
1591
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
812
1592
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
813
1593
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
814
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
815
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1594
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
1595
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
816
1596
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
817
- }).toMatchSnapshot();
1597
+ }).toMatchInlineSnapshot(`
1598
+ {
1599
+ "authenticationCheckCalls": [],
1600
+ "oAuth2AccessTokenCheckCalls": [],
1601
+ "oAuth2AccessTokenCreateCalls": [],
1602
+ "oAuth2AuthorizationCodeCheckCalls": [],
1603
+ "oAuth2AuthorizationCodeCreateCalls": [],
1604
+ "oAuth2PasswordCheckCalls": [],
1605
+ "oAuth2RefreshTokenCheckCalls": [],
1606
+ "oAuth2RefreshTokenCreateCalls": [],
1607
+ "readClientGrantsCalls": [
1608
+ [
1609
+ "the_client_id",
1610
+ ],
1611
+ ],
1612
+ "response": {
1613
+ "data": "",
1614
+ "headers": {
1615
+ "connection": undefined,
1616
+ "date": undefined,
1617
+ "etag": undefined,
1618
+ "keep-alive": undefined,
1619
+ "last-modified": undefined,
1620
+ "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",
1621
+ "server": undefined,
1622
+ "transaction-id": "10",
1623
+ "transfer-encoding": "chunked",
1624
+ },
1625
+ "status": 302,
1626
+ },
1627
+ }
1628
+ `);
818
1629
  });
819
1630
  test('should redirect with a token', async () => {
820
1631
  time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
@@ -822,30 +1633,43 @@ describe('OAuth2 server', () => {
822
1633
  oAuth2AccessToken.check,
823
1634
  oAuth2RefreshToken.check,
824
1635
  oAuth2RefreshToken.create,
825
- oAuth2Code.check,
826
- oAuth2Code.create,
1636
+ oAuth2AuthorizationCode.check,
1637
+ oAuth2AuthorizationCode.create,
827
1638
  oAuth2Password.check,
828
1639
  ].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
829
1640
  authentication.check.mockResolvedValueOnce({
830
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
831
- scope: 'user,oauth',
832
- userId: '2',
1641
+ clientId: 'the_root_client_id',
1642
+ scopes: ['user', 'oauth'],
1643
+ userId: 'auth_user_id',
833
1644
  });
834
1645
  oAuth2AccessToken.create.mockResolvedValueOnce({
835
1646
  token: 'an_access_token',
836
1647
  expiresAt: Date.parse('2010-03-07T00:00:00Z'),
837
1648
  });
838
- checkApplication.mockResolvedValueOnce({
839
- type: 'implicit',
840
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
841
- scope: 'user,oauth',
842
- redirectURI: 'http://redirect.example.com/yolo',
1649
+ readClientGrants.mockResolvedValueOnce({
1650
+ allowedGrantTypes: ['password'],
1651
+ allowedScopes: [],
1652
+ allowedRedirectURIS: [],
1653
+ isPublicClient: false,
1654
+ canAcknowledge: true,
1655
+ authenticationData: {
1656
+ clientId: 'the_root_client_id',
1657
+ scopes: [],
1658
+ userId: 'a_user_id',
1659
+ },
843
1660
  });
844
- checkApplication.mockResolvedValueOnce({
845
- type: 'implicit',
846
- applicationId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
847
- scope: 'user,oauth',
848
- redirectURI: 'http://redirect.example.com/yolo',
1661
+ readClientGrants.mockResolvedValueOnce({
1662
+ allowedGrantTypes: ['implicit'],
1663
+ allowedScopes: ['user', 'oauth'],
1664
+ allowedRedirectURIS: [
1665
+ 'http://redirect.example.com/yolo?a_param=a_value',
1666
+ ],
1667
+ isPublicClient: true,
1668
+ authenticationData: {
1669
+ clientId: 'the_client_id',
1670
+ scopes: ['user', 'oauth'],
1671
+ userId: 'a_user_id',
1672
+ },
849
1673
  });
850
1674
  const { status, headers, data } = await axios({
851
1675
  method: 'post',
@@ -855,7 +1679,7 @@ describe('OAuth2 server', () => {
855
1679
  },
856
1680
  data: {
857
1681
  responseType: 'token',
858
- clientId: 'acdc41ce-acdc-41ce-acdc-41ceacdc41ce',
1682
+ clientId: 'the_client_id',
859
1683
  redirectURI: 'http://redirect.example.com/yolo?a_param=a_value',
860
1684
  scope: 'user',
861
1685
  state: 'xyz',
@@ -865,47 +1689,82 @@ describe('OAuth2 server', () => {
865
1689
  validateStatus: () => true,
866
1690
  });
867
1691
  expect({
868
- status,
869
- headers: {
870
- ...headers,
871
- // Erasing the Date header that may be added by Axios :/
872
- date: undefined,
873
- etag: undefined,
874
- 'last-modified': undefined,
875
- server: undefined,
876
- connection: undefined,
877
- 'keep-alive': undefined,
878
- },
879
- data,
880
- }).toMatchInlineSnapshot(`
881
- {
882
- "data": "",
883
- "headers": {
884
- "connection": undefined,
885
- "date": undefined,
886
- "etag": undefined,
887
- "keep-alive": undefined,
888
- "last-modified": undefined,
889
- "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",
890
- "server": undefined,
891
- "transaction-id": "7",
892
- "transfer-encoding": "chunked",
893
- "x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
894
- },
895
- "status": 302,
896
- }
897
- `);
898
- expect({
899
- checkApplicationCalls: checkApplication.mock.calls,
1692
+ response: {
1693
+ status,
1694
+ headers: {
1695
+ ...headers,
1696
+ // Erasing the Date header that may be added by Axios :/
1697
+ date: undefined,
1698
+ etag: undefined,
1699
+ 'last-modified': undefined,
1700
+ server: undefined,
1701
+ connection: undefined,
1702
+ 'keep-alive': undefined,
1703
+ },
1704
+ data,
1705
+ },
1706
+ readClientGrantsCalls: readClientGrants.mock.calls,
900
1707
  authenticationCheckCalls: authentication.check.mock.calls,
901
1708
  oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
902
1709
  oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
903
1710
  oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
904
1711
  oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
905
- oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
906
- oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
1712
+ oAuth2AuthorizationCodeCheckCalls: oAuth2AuthorizationCode.check.mock.calls,
1713
+ oAuth2AuthorizationCodeCreateCalls: oAuth2AuthorizationCode.create.mock.calls,
907
1714
  oAuth2PasswordCheckCalls: oAuth2Password.check.mock.calls,
908
- }).toMatchSnapshot();
1715
+ }).toMatchInlineSnapshot(`
1716
+ {
1717
+ "authenticationCheckCalls": [
1718
+ [
1719
+ "bearer",
1720
+ {
1721
+ "hash": "yolo",
1722
+ },
1723
+ ],
1724
+ ],
1725
+ "oAuth2AccessTokenCheckCalls": [],
1726
+ "oAuth2AccessTokenCreateCalls": [
1727
+ [
1728
+ {
1729
+ "clientId": "the_client_id",
1730
+ "scopes": [
1731
+ "user",
1732
+ ],
1733
+ "userId": "auth_user_id",
1734
+ },
1735
+ ],
1736
+ ],
1737
+ "oAuth2AuthorizationCodeCheckCalls": [],
1738
+ "oAuth2AuthorizationCodeCreateCalls": [],
1739
+ "oAuth2PasswordCheckCalls": [],
1740
+ "oAuth2RefreshTokenCheckCalls": [],
1741
+ "oAuth2RefreshTokenCreateCalls": [],
1742
+ "readClientGrantsCalls": [
1743
+ [
1744
+ "the_root_client_id",
1745
+ ],
1746
+ [
1747
+ "the_client_id",
1748
+ ],
1749
+ ],
1750
+ "response": {
1751
+ "data": "",
1752
+ "headers": {
1753
+ "connection": undefined,
1754
+ "date": undefined,
1755
+ "etag": undefined,
1756
+ "keep-alive": undefined,
1757
+ "last-modified": undefined,
1758
+ "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",
1759
+ "server": undefined,
1760
+ "transaction-id": "11",
1761
+ "transfer-encoding": "chunked",
1762
+ "x-authenticated": "{"clientId":"the_root_client_id","scopes":["user","oauth"],"userId":"auth_user_id"}",
1763
+ },
1764
+ "status": 201,
1765
+ },
1766
+ }
1767
+ `);
909
1768
  });
910
1769
  });
911
1770
  });