@whook/oauth2 25.2.1 → 26.0.2

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