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