@whook/oauth2 25.2.0 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -98
- package/dist/index.d.ts +30 -11
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1258 -399
- package/dist/index.test.js.map +1 -1
- 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 +113 -0
- package/dist/libs/errors.js +178 -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 +7 -0
- package/dist/libs/redirectURI.js +78 -0
- package/dist/libs/redirectURI.js.map +1 -0
- package/dist/libs/schemas.d.ts +23 -0
- package/dist/libs/schemas.js +25 -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 +7 -0
- package/dist/libs/verifier.js +37 -0
- package/dist/libs/verifier.js.map +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 +13 -50
- package/dist/routes/getOAuth2Authorize.js +60 -86
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +147 -68
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +8 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js +20 -9
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +38 -37
- 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 +20 -10
- package/dist/routes/postOAuth2Acknowledge.js +54 -38
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.test.js +137 -72
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
- 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 +35 -108
- package/dist/routes/postOAuth2Token.js +53 -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 +1 -1
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +129 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js +221 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +474 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.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 +81 -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 +72 -0
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.js +727 -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 +11 -11
- package/src/index.test.ts +1314 -404
- package/src/index.ts +46 -53
- package/src/libs/clients.ts +22 -0
- package/src/libs/errors.ts +325 -0
- package/src/libs/grants.ts +15 -0
- package/src/libs/redirectURI.ts +120 -0
- package/src/libs/schemas.ts +27 -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 +57 -0
- package/src/routes/getOAuth2Authorize.test.ts +179 -96
- package/src/routes/getOAuth2Authorize.ts +97 -124
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +58 -60
- package/src/routes/getOAuth2WellKnownMetadata.ts +26 -11
- 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 +169 -110
- package/src/routes/postOAuth2Acknowledge.ts +101 -61
- 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 +92 -136
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +16 -18
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +564 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +388 -0
- package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
- package/src/services/oAuth2Granters.ts +101 -195
- package/src/services/oAuth2ImplicitGranter.test.ts +811 -0
- package/src/services/oAuth2ImplicitGranter.ts +163 -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/verifier.test.d.ts} +0 -0
|
@@ -3,111 +3,90 @@ import initPostOAuth2Token from './postOAuth2Token.js';
|
|
|
3
3
|
import { YError } from 'yerror';
|
|
4
4
|
import { type LogService, type TimeService } from 'common-services';
|
|
5
5
|
import {
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
type
|
|
6
|
+
type WhookOAuth2GranterService,
|
|
7
|
+
type WhookOAuth2AccessTokenService,
|
|
8
|
+
type WhookOAuth2RefreshTokenService,
|
|
9
|
+
type WhookOAuth2Options,
|
|
10
|
+
type WhookOAuth2GranterDefinitions,
|
|
11
|
+
type WhookOAuth2ClientCredentialsGranterService,
|
|
9
12
|
} from '../index.js';
|
|
10
|
-
import { type
|
|
11
|
-
import { type
|
|
12
|
-
import { type
|
|
13
|
-
import { type
|
|
13
|
+
import { type WhookOAuth2AuthorizationCodeGranterService } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
14
|
+
import { type WhookOAuth2ImplicitGranterService } from '../services/oAuth2ImplicitGranter.js';
|
|
15
|
+
import { type WhookOAuth2PasswordGranterService } from '../services/oAuth2PasswordGranter.js';
|
|
16
|
+
import { type WhookOAuth2RefreshTokenGranterService } from '../services/oAuth2RefreshTokenGranter.js';
|
|
14
17
|
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
15
18
|
|
|
16
19
|
describe('postOAuth2Token', () => {
|
|
20
|
+
const OAUTH2: WhookOAuth2Options = {
|
|
21
|
+
authenticateURL: 'https://auth.example.com/sign_in',
|
|
22
|
+
allowedScopes: ['user'],
|
|
23
|
+
rootClientId: 'abbacaca-abba-caca-abba-cacaabbac0c0',
|
|
24
|
+
};
|
|
17
25
|
const log = jest.fn<LogService>();
|
|
18
26
|
const time = jest.fn<TimeService>();
|
|
19
27
|
const oAuth2AccessToken = {
|
|
20
|
-
create: jest.fn<
|
|
21
|
-
check: jest.fn<
|
|
28
|
+
create: jest.fn<WhookOAuth2AccessTokenService['create']>(),
|
|
29
|
+
check: jest.fn<WhookOAuth2AccessTokenService['check']>(),
|
|
22
30
|
};
|
|
23
31
|
const oAuth2RefreshToken = {
|
|
24
|
-
create: jest.fn<
|
|
25
|
-
check: jest.fn<
|
|
32
|
+
create: jest.fn<WhookOAuth2RefreshTokenService['create']>(),
|
|
33
|
+
check: jest.fn<WhookOAuth2RefreshTokenService['check']>(),
|
|
26
34
|
};
|
|
27
35
|
const codeGranter = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
grantType: 'authorization_code',
|
|
45
|
-
authenticate:
|
|
46
|
-
jest.fn<
|
|
47
|
-
NonNullable<OAuth2CodeGranterService['authenticator']>['authenticate']
|
|
48
|
-
>(),
|
|
49
|
-
},
|
|
50
|
-
};
|
|
36
|
+
grantType: 'authorization_code',
|
|
37
|
+
responseType: 'code',
|
|
38
|
+
issuesRefreshToken: true,
|
|
39
|
+
authorize:
|
|
40
|
+
jest.fn<
|
|
41
|
+
NonNullable<WhookOAuth2AuthorizationCodeGranterService['authorize']>
|
|
42
|
+
>(),
|
|
43
|
+
acknowledge:
|
|
44
|
+
jest.fn<
|
|
45
|
+
NonNullable<WhookOAuth2AuthorizationCodeGranterService['acknowledge']>
|
|
46
|
+
>(),
|
|
47
|
+
authenticate:
|
|
48
|
+
jest.fn<
|
|
49
|
+
NonNullable<WhookOAuth2AuthorizationCodeGranterService['authenticate']>
|
|
50
|
+
>(),
|
|
51
|
+
} satisfies WhookOAuth2AuthorizationCodeGranterService;
|
|
51
52
|
const passwordGranter = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
authenticate
|
|
56
|
-
|
|
57
|
-
NonNullable<
|
|
58
|
-
OAuth2PasswordGranterService['authenticator']
|
|
59
|
-
>['authenticate']
|
|
60
|
-
>(),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
53
|
+
grantType: 'password',
|
|
54
|
+
issuesRefreshToken: false,
|
|
55
|
+
authenticate:
|
|
56
|
+
jest.fn<NonNullable<WhookOAuth2PasswordGranterService['authenticate']>>(),
|
|
57
|
+
} satisfies WhookOAuth2PasswordGranterService;
|
|
63
58
|
const clientCredentialsGranter = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
};
|
|
59
|
+
grantType: 'client_credentials',
|
|
60
|
+
issuesRefreshToken: false,
|
|
61
|
+
authenticate:
|
|
62
|
+
jest.fn<
|
|
63
|
+
NonNullable<WhookOAuth2ClientCredentialsGranterService['authenticate']>
|
|
64
|
+
>(),
|
|
65
|
+
} satisfies WhookOAuth2ClientCredentialsGranterService;
|
|
73
66
|
const tokenGranter = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
>(),
|
|
83
|
-
},
|
|
84
|
-
acknowledger: {
|
|
85
|
-
acknowledgmentType: 'token',
|
|
86
|
-
acknowledge:
|
|
87
|
-
jest.fn<
|
|
88
|
-
NonNullable<OAuth2TokenGranterService['acknowledger']>['acknowledge']
|
|
89
|
-
>(),
|
|
90
|
-
},
|
|
91
|
-
};
|
|
67
|
+
grantType: 'implicit',
|
|
68
|
+
responseType: 'token',
|
|
69
|
+
issuesRefreshToken: false,
|
|
70
|
+
authorize:
|
|
71
|
+
jest.fn<NonNullable<WhookOAuth2ImplicitGranterService['authorize']>>(),
|
|
72
|
+
acknowledge:
|
|
73
|
+
jest.fn<NonNullable<WhookOAuth2ImplicitGranterService['acknowledge']>>(),
|
|
74
|
+
} satisfies WhookOAuth2ImplicitGranterService;
|
|
92
75
|
const refreshTokenGranter = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
>['authenticate']
|
|
101
|
-
>(),
|
|
102
|
-
},
|
|
103
|
-
};
|
|
76
|
+
grantType: 'refresh_token',
|
|
77
|
+
issuesRefreshToken: true,
|
|
78
|
+
authenticate:
|
|
79
|
+
jest.fn<
|
|
80
|
+
NonNullable<WhookOAuth2RefreshTokenGranterService['authenticate']>
|
|
81
|
+
>(),
|
|
82
|
+
} satisfies WhookOAuth2RefreshTokenGranterService;
|
|
104
83
|
const oAuth2Granters = [
|
|
105
84
|
codeGranter,
|
|
106
85
|
tokenGranter,
|
|
107
86
|
passwordGranter,
|
|
108
87
|
refreshTokenGranter,
|
|
109
88
|
clientCredentialsGranter,
|
|
110
|
-
] as unknown as
|
|
89
|
+
] as unknown as WhookOAuth2GranterService<WhookOAuth2GranterDefinitions>[];
|
|
111
90
|
|
|
112
91
|
beforeEach(() => {
|
|
113
92
|
log.mockReset();
|
|
@@ -116,17 +95,17 @@ describe('postOAuth2Token', () => {
|
|
|
116
95
|
oAuth2AccessToken.check.mockReset();
|
|
117
96
|
oAuth2RefreshToken.create.mockReset();
|
|
118
97
|
oAuth2RefreshToken.check.mockReset();
|
|
119
|
-
codeGranter.
|
|
120
|
-
codeGranter.
|
|
121
|
-
codeGranter.
|
|
122
|
-
tokenGranter.
|
|
123
|
-
tokenGranter.
|
|
124
|
-
passwordGranter.
|
|
125
|
-
refreshTokenGranter.
|
|
126
|
-
clientCredentialsGranter.
|
|
98
|
+
codeGranter.authorize.mockReset();
|
|
99
|
+
codeGranter.acknowledge.mockReset();
|
|
100
|
+
codeGranter.authenticate.mockReset();
|
|
101
|
+
tokenGranter.authorize.mockReset();
|
|
102
|
+
tokenGranter.acknowledge.mockReset();
|
|
103
|
+
passwordGranter.authenticate.mockReset();
|
|
104
|
+
refreshTokenGranter.authenticate.mockReset();
|
|
105
|
+
clientCredentialsGranter.authenticate.mockReset();
|
|
127
106
|
});
|
|
128
107
|
|
|
129
|
-
test('should create a token', async () => {
|
|
108
|
+
test('should create a token with the code flow', async () => {
|
|
130
109
|
time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());
|
|
131
110
|
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
132
111
|
token: 'an_access_token',
|
|
@@ -136,13 +115,14 @@ describe('postOAuth2Token', () => {
|
|
|
136
115
|
token: 'a_refresh_token',
|
|
137
116
|
expiresAt: Date.parse('2180-03-06T00:00:00Z'),
|
|
138
117
|
});
|
|
139
|
-
codeGranter.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
118
|
+
codeGranter.authenticate.mockResolvedValueOnce({
|
|
119
|
+
clientId: 'authenticate_app_id',
|
|
120
|
+
userId: 'authenticate_user_id',
|
|
121
|
+
scopes: ['user', 'admin'],
|
|
143
122
|
});
|
|
144
123
|
|
|
145
124
|
const postOAuth2Token = await initPostOAuth2Token({
|
|
125
|
+
OAUTH2,
|
|
146
126
|
oAuth2Granters,
|
|
147
127
|
oAuth2AccessToken,
|
|
148
128
|
oAuth2RefreshToken,
|
|
@@ -151,8 +131,8 @@ describe('postOAuth2Token', () => {
|
|
|
151
131
|
});
|
|
152
132
|
const response = await postOAuth2Token({
|
|
153
133
|
authenticationData: {
|
|
154
|
-
|
|
155
|
-
|
|
134
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
135
|
+
scopes: ['user'],
|
|
156
136
|
} as WhookAuthenticationData,
|
|
157
137
|
body: {
|
|
158
138
|
grant_type: 'authorization_code',
|
|
@@ -164,13 +144,462 @@ describe('postOAuth2Token', () => {
|
|
|
164
144
|
expect({
|
|
165
145
|
response,
|
|
166
146
|
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
147
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
148
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
149
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
150
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
|
|
151
|
+
codeGranterAcknowledgerAcknowledgeCalls:
|
|
152
|
+
codeGranter.acknowledge.mock.calls,
|
|
153
|
+
codeGranterAuthenticatorAuthenticateCalls:
|
|
154
|
+
codeGranter.authenticate.mock.calls,
|
|
155
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
|
|
156
|
+
tokenGranterAcknowledgerAcknowledgeCalls:
|
|
157
|
+
tokenGranter.acknowledge.mock.calls,
|
|
158
|
+
passwordGranterAuthenticatorAuthenticateCalls:
|
|
159
|
+
passwordGranter.authenticate.mock.calls,
|
|
160
|
+
refreshTokenGranterAuthenticatorAuthenticateCalls:
|
|
161
|
+
refreshTokenGranter.authenticate.mock.calls,
|
|
162
|
+
clientCredentialsGranterAuthenticatorAuthenticateCalls:
|
|
163
|
+
clientCredentialsGranter.authenticate.mock.calls,
|
|
164
|
+
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
165
|
+
}).toMatchInlineSnapshot(`
|
|
166
|
+
{
|
|
167
|
+
"clientCredentialsGranterAuthenticatorAuthenticateCalls": [],
|
|
168
|
+
"codeGranterAcknowledgerAcknowledgeCalls": [],
|
|
169
|
+
"codeGranterAuthenticatorAuthenticateCalls": [
|
|
170
|
+
[
|
|
171
|
+
{
|
|
172
|
+
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
173
|
+
"code": "007",
|
|
174
|
+
"demandedScopes": [],
|
|
175
|
+
"redirectURI": "http://lol",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
179
|
+
"scopes": [
|
|
180
|
+
"user",
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
],
|
|
185
|
+
"codeGranterAuthorizerAuthorizeCalls": [],
|
|
186
|
+
"logCalls": [],
|
|
187
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
188
|
+
"oAuth2AccessTokenCreateCalls": [
|
|
189
|
+
[
|
|
190
|
+
{
|
|
191
|
+
"clientId": "authenticate_app_id",
|
|
192
|
+
"scopes": [
|
|
193
|
+
"user",
|
|
194
|
+
"admin",
|
|
195
|
+
],
|
|
196
|
+
"userId": "authenticate_user_id",
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
],
|
|
200
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
201
|
+
"oAuth2RefreshTokenCreateCalls": [
|
|
202
|
+
[
|
|
203
|
+
{
|
|
204
|
+
"clientId": "authenticate_app_id",
|
|
205
|
+
"scopes": [
|
|
206
|
+
"user",
|
|
207
|
+
"admin",
|
|
208
|
+
],
|
|
209
|
+
"userId": "authenticate_user_id",
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
],
|
|
213
|
+
"passwordGranterAuthenticatorAuthenticateCalls": [],
|
|
214
|
+
"refreshTokenGranterAuthenticatorAuthenticateCalls": [],
|
|
215
|
+
"response": {
|
|
216
|
+
"body": {
|
|
217
|
+
"access_token": "an_access_token",
|
|
218
|
+
"expiration_date": "2010-03-07T00:00:00.000Z",
|
|
219
|
+
"expires_in": 86400,
|
|
220
|
+
"refresh_token": "a_refresh_token",
|
|
221
|
+
"refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
|
|
222
|
+
"refresh_token_expires_in": 5364748800,
|
|
223
|
+
"scope": "user admin",
|
|
224
|
+
"token_type": "bearer",
|
|
225
|
+
},
|
|
226
|
+
"headers": {
|
|
227
|
+
"Cache-Control": "no-store",
|
|
228
|
+
"Pragma": "no-cache",
|
|
229
|
+
},
|
|
230
|
+
"status": 200,
|
|
231
|
+
},
|
|
232
|
+
"tokenGranterAcknowledgerAcknowledgeCalls": [],
|
|
233
|
+
"tokenGranterAuthorizerAuthorizeCalls": [],
|
|
234
|
+
}
|
|
235
|
+
`);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('should create a token with the client_credentials flow', async () => {
|
|
239
|
+
time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());
|
|
240
|
+
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
241
|
+
token: 'an_access_token',
|
|
242
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
243
|
+
});
|
|
244
|
+
oAuth2RefreshToken.create.mockResolvedValueOnce({
|
|
245
|
+
token: 'a_refresh_token',
|
|
246
|
+
expiresAt: Date.parse('2180-03-06T00:00:00Z'),
|
|
247
|
+
});
|
|
248
|
+
clientCredentialsGranter.authenticate.mockResolvedValueOnce({
|
|
249
|
+
clientId: 'authenticate_app_id',
|
|
250
|
+
scopes: ['user', 'admin'],
|
|
251
|
+
userId: 'a_user_id',
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const postOAuth2Token = await initPostOAuth2Token({
|
|
255
|
+
OAUTH2,
|
|
256
|
+
oAuth2Granters,
|
|
257
|
+
oAuth2AccessToken,
|
|
258
|
+
oAuth2RefreshToken,
|
|
259
|
+
time,
|
|
260
|
+
log,
|
|
261
|
+
});
|
|
262
|
+
const response = await postOAuth2Token({
|
|
263
|
+
authenticationData: {
|
|
264
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
265
|
+
scopes: ['user'],
|
|
266
|
+
} as WhookAuthenticationData,
|
|
267
|
+
body: {
|
|
268
|
+
grant_type: 'client_credentials',
|
|
269
|
+
scope: 'user',
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
expect({
|
|
274
|
+
response,
|
|
275
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
276
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
277
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
278
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
279
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
|
|
280
|
+
codeGranterAcknowledgerAcknowledgeCalls:
|
|
281
|
+
codeGranter.acknowledge.mock.calls,
|
|
282
|
+
codeGranterAuthenticatorAuthenticateCalls:
|
|
283
|
+
codeGranter.authenticate.mock.calls,
|
|
284
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
|
|
285
|
+
tokenGranterAcknowledgerAcknowledgeCalls:
|
|
286
|
+
tokenGranter.acknowledge.mock.calls,
|
|
287
|
+
passwordGranterAuthenticatorAuthenticateCalls:
|
|
288
|
+
passwordGranter.authenticate.mock.calls,
|
|
289
|
+
refreshTokenGranterAuthenticatorAuthenticateCalls:
|
|
290
|
+
refreshTokenGranter.authenticate.mock.calls,
|
|
291
|
+
clientCredentialsGranterAuthenticatorAuthenticateCalls:
|
|
292
|
+
clientCredentialsGranter.authenticate.mock.calls,
|
|
293
|
+
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
294
|
+
}).toMatchInlineSnapshot(`
|
|
295
|
+
{
|
|
296
|
+
"clientCredentialsGranterAuthenticatorAuthenticateCalls": [
|
|
297
|
+
[
|
|
298
|
+
{
|
|
299
|
+
"demandedScopes": [
|
|
300
|
+
"user",
|
|
301
|
+
],
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
305
|
+
"scopes": [
|
|
306
|
+
"user",
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
],
|
|
311
|
+
"codeGranterAcknowledgerAcknowledgeCalls": [],
|
|
312
|
+
"codeGranterAuthenticatorAuthenticateCalls": [],
|
|
313
|
+
"codeGranterAuthorizerAuthorizeCalls": [],
|
|
314
|
+
"logCalls": [],
|
|
315
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
316
|
+
"oAuth2AccessTokenCreateCalls": [
|
|
317
|
+
[
|
|
318
|
+
{
|
|
319
|
+
"clientId": "authenticate_app_id",
|
|
320
|
+
"scopes": [
|
|
321
|
+
"user",
|
|
322
|
+
"admin",
|
|
323
|
+
],
|
|
324
|
+
"userId": "a_user_id",
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
],
|
|
328
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
329
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
330
|
+
"passwordGranterAuthenticatorAuthenticateCalls": [],
|
|
331
|
+
"refreshTokenGranterAuthenticatorAuthenticateCalls": [],
|
|
332
|
+
"response": {
|
|
333
|
+
"body": {
|
|
334
|
+
"access_token": "an_access_token",
|
|
335
|
+
"expiration_date": "2010-03-07T00:00:00.000Z",
|
|
336
|
+
"expires_in": 86400,
|
|
337
|
+
"scope": "user admin",
|
|
338
|
+
"token_type": "bearer",
|
|
339
|
+
},
|
|
340
|
+
"headers": {
|
|
341
|
+
"Cache-Control": "no-store",
|
|
342
|
+
"Pragma": "no-cache",
|
|
343
|
+
},
|
|
344
|
+
"status": 200,
|
|
345
|
+
},
|
|
346
|
+
"tokenGranterAcknowledgerAcknowledgeCalls": [],
|
|
347
|
+
"tokenGranterAuthorizerAuthorizeCalls": [],
|
|
348
|
+
}
|
|
349
|
+
`);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('should create a token with the refresh_token flow', async () => {
|
|
353
|
+
time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());
|
|
354
|
+
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
355
|
+
token: 'an_access_token',
|
|
356
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
357
|
+
});
|
|
358
|
+
oAuth2RefreshToken.create.mockResolvedValueOnce({
|
|
359
|
+
token: 'a_refresh_token',
|
|
360
|
+
expiresAt: Date.parse('2180-03-06T00:00:00Z'),
|
|
361
|
+
});
|
|
362
|
+
refreshTokenGranter.authenticate.mockResolvedValueOnce({
|
|
363
|
+
clientId: 'authenticate_app_id',
|
|
364
|
+
userId: 'authenticate_user_id',
|
|
365
|
+
scopes: ['user', 'admin'],
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const postOAuth2Token = await initPostOAuth2Token({
|
|
369
|
+
OAUTH2,
|
|
370
|
+
oAuth2Granters,
|
|
371
|
+
oAuth2AccessToken,
|
|
372
|
+
oAuth2RefreshToken,
|
|
373
|
+
time,
|
|
374
|
+
log,
|
|
375
|
+
});
|
|
376
|
+
const response = await postOAuth2Token({
|
|
377
|
+
authenticationData: {
|
|
378
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
379
|
+
scopes: ['user'],
|
|
380
|
+
} as WhookAuthenticationData,
|
|
381
|
+
body: {
|
|
382
|
+
grant_type: 'refresh_token',
|
|
383
|
+
refresh_token: 'a_refresh_token',
|
|
384
|
+
scope: 'user',
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
expect({
|
|
389
|
+
response,
|
|
390
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
391
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
392
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
393
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
394
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
|
|
395
|
+
codeGranterAcknowledgerAcknowledgeCalls:
|
|
396
|
+
codeGranter.acknowledge.mock.calls,
|
|
397
|
+
codeGranterAuthenticatorAuthenticateCalls:
|
|
398
|
+
codeGranter.authenticate.mock.calls,
|
|
399
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
|
|
400
|
+
tokenGranterAcknowledgerAcknowledgeCalls:
|
|
401
|
+
tokenGranter.acknowledge.mock.calls,
|
|
402
|
+
passwordGranterAuthenticatorAuthenticateCalls:
|
|
403
|
+
passwordGranter.authenticate.mock.calls,
|
|
404
|
+
refreshTokenGranterAuthenticatorAuthenticateCalls:
|
|
405
|
+
refreshTokenGranter.authenticate.mock.calls,
|
|
406
|
+
clientCredentialsGranterAuthenticatorAuthenticateCalls:
|
|
407
|
+
clientCredentialsGranter.authenticate.mock.calls,
|
|
408
|
+
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
409
|
+
}).toMatchInlineSnapshot(`
|
|
410
|
+
{
|
|
411
|
+
"clientCredentialsGranterAuthenticatorAuthenticateCalls": [],
|
|
412
|
+
"codeGranterAcknowledgerAcknowledgeCalls": [],
|
|
413
|
+
"codeGranterAuthenticatorAuthenticateCalls": [],
|
|
414
|
+
"codeGranterAuthorizerAuthorizeCalls": [],
|
|
415
|
+
"logCalls": [],
|
|
416
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
417
|
+
"oAuth2AccessTokenCreateCalls": [
|
|
418
|
+
[
|
|
419
|
+
{
|
|
420
|
+
"clientId": "authenticate_app_id",
|
|
421
|
+
"scopes": [
|
|
422
|
+
"user",
|
|
423
|
+
"admin",
|
|
424
|
+
],
|
|
425
|
+
"userId": "authenticate_user_id",
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
],
|
|
429
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
430
|
+
"oAuth2RefreshTokenCreateCalls": [
|
|
431
|
+
[
|
|
432
|
+
{
|
|
433
|
+
"clientId": "authenticate_app_id",
|
|
434
|
+
"scopes": [
|
|
435
|
+
"user",
|
|
436
|
+
"admin",
|
|
437
|
+
],
|
|
438
|
+
"userId": "authenticate_user_id",
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
],
|
|
442
|
+
"passwordGranterAuthenticatorAuthenticateCalls": [],
|
|
443
|
+
"refreshTokenGranterAuthenticatorAuthenticateCalls": [
|
|
444
|
+
[
|
|
445
|
+
{
|
|
446
|
+
"demandedScopes": [
|
|
447
|
+
"user",
|
|
448
|
+
],
|
|
449
|
+
"refreshToken": "a_refresh_token",
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
453
|
+
"scopes": [
|
|
454
|
+
"user",
|
|
455
|
+
],
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
],
|
|
459
|
+
"response": {
|
|
460
|
+
"body": {
|
|
461
|
+
"access_token": "an_access_token",
|
|
462
|
+
"expiration_date": "2010-03-07T00:00:00.000Z",
|
|
463
|
+
"expires_in": 86400,
|
|
464
|
+
"refresh_token": "a_refresh_token",
|
|
465
|
+
"refresh_token_expiration_date": "2180-03-06T00:00:00.000Z",
|
|
466
|
+
"refresh_token_expires_in": 5364748800,
|
|
467
|
+
"scope": "user admin",
|
|
468
|
+
"token_type": "bearer",
|
|
469
|
+
},
|
|
470
|
+
"headers": {
|
|
471
|
+
"Cache-Control": "no-store",
|
|
472
|
+
"Pragma": "no-cache",
|
|
473
|
+
},
|
|
474
|
+
"status": 200,
|
|
475
|
+
},
|
|
476
|
+
"tokenGranterAcknowledgerAcknowledgeCalls": [],
|
|
477
|
+
"tokenGranterAuthorizerAuthorizeCalls": [],
|
|
478
|
+
}
|
|
479
|
+
`);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
test('should create a token with the password flow', async () => {
|
|
483
|
+
time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());
|
|
484
|
+
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
485
|
+
token: 'an_access_token',
|
|
486
|
+
expiresAt: Date.parse('2010-03-07T00:00:00Z'),
|
|
487
|
+
});
|
|
488
|
+
oAuth2RefreshToken.create.mockResolvedValueOnce({
|
|
489
|
+
token: 'a_refresh_token',
|
|
490
|
+
expiresAt: Date.parse('2180-03-06T00:00:00Z'),
|
|
491
|
+
});
|
|
492
|
+
passwordGranter.authenticate.mockResolvedValueOnce({
|
|
493
|
+
clientId: 'authenticate_app_id',
|
|
494
|
+
userId: 'authenticate_user_id',
|
|
495
|
+
scopes: ['user', 'admin'],
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
const postOAuth2Token = await initPostOAuth2Token({
|
|
499
|
+
OAUTH2,
|
|
500
|
+
oAuth2Granters,
|
|
501
|
+
oAuth2AccessToken,
|
|
502
|
+
oAuth2RefreshToken,
|
|
503
|
+
time,
|
|
504
|
+
log,
|
|
505
|
+
});
|
|
506
|
+
const response = await postOAuth2Token({
|
|
507
|
+
authenticationData: {
|
|
508
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
509
|
+
scopes: ['user'],
|
|
510
|
+
} as WhookAuthenticationData,
|
|
511
|
+
body: {
|
|
512
|
+
grant_type: 'password',
|
|
513
|
+
username: 'a_username',
|
|
514
|
+
password: 'a_password',
|
|
515
|
+
scope: 'user',
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
expect({
|
|
520
|
+
response,
|
|
521
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
522
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
167
523
|
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
524
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
525
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
|
|
526
|
+
codeGranterAcknowledgerAcknowledgeCalls:
|
|
527
|
+
codeGranter.acknowledge.mock.calls,
|
|
528
|
+
codeGranterAuthenticatorAuthenticateCalls:
|
|
529
|
+
codeGranter.authenticate.mock.calls,
|
|
530
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
|
|
531
|
+
tokenGranterAcknowledgerAcknowledgeCalls:
|
|
532
|
+
tokenGranter.acknowledge.mock.calls,
|
|
533
|
+
passwordGranterAuthenticatorAuthenticateCalls:
|
|
534
|
+
passwordGranter.authenticate.mock.calls,
|
|
535
|
+
refreshTokenGranterAuthenticatorAuthenticateCalls:
|
|
536
|
+
refreshTokenGranter.authenticate.mock.calls,
|
|
537
|
+
clientCredentialsGranterAuthenticatorAuthenticateCalls:
|
|
538
|
+
clientCredentialsGranter.authenticate.mock.calls,
|
|
168
539
|
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
169
|
-
}).
|
|
540
|
+
}).toMatchInlineSnapshot(`
|
|
541
|
+
{
|
|
542
|
+
"clientCredentialsGranterAuthenticatorAuthenticateCalls": [],
|
|
543
|
+
"codeGranterAcknowledgerAcknowledgeCalls": [],
|
|
544
|
+
"codeGranterAuthenticatorAuthenticateCalls": [],
|
|
545
|
+
"codeGranterAuthorizerAuthorizeCalls": [],
|
|
546
|
+
"logCalls": [],
|
|
547
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
548
|
+
"oAuth2AccessTokenCreateCalls": [
|
|
549
|
+
[
|
|
550
|
+
{
|
|
551
|
+
"clientId": "authenticate_app_id",
|
|
552
|
+
"scopes": [
|
|
553
|
+
"user",
|
|
554
|
+
"admin",
|
|
555
|
+
],
|
|
556
|
+
"userId": "authenticate_user_id",
|
|
557
|
+
},
|
|
558
|
+
],
|
|
559
|
+
],
|
|
560
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
561
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
562
|
+
"passwordGranterAuthenticatorAuthenticateCalls": [
|
|
563
|
+
[
|
|
564
|
+
{
|
|
565
|
+
"demandedScopes": [
|
|
566
|
+
"user",
|
|
567
|
+
],
|
|
568
|
+
"password": "a_password",
|
|
569
|
+
"username": "a_username",
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
"clientId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
573
|
+
"scopes": [
|
|
574
|
+
"user",
|
|
575
|
+
],
|
|
576
|
+
},
|
|
577
|
+
],
|
|
578
|
+
],
|
|
579
|
+
"refreshTokenGranterAuthenticatorAuthenticateCalls": [],
|
|
580
|
+
"response": {
|
|
581
|
+
"body": {
|
|
582
|
+
"access_token": "an_access_token",
|
|
583
|
+
"expiration_date": "2010-03-07T00:00:00.000Z",
|
|
584
|
+
"expires_in": 86400,
|
|
585
|
+
"scope": "user admin",
|
|
586
|
+
"token_type": "bearer",
|
|
587
|
+
},
|
|
588
|
+
"headers": {
|
|
589
|
+
"Cache-Control": "no-store",
|
|
590
|
+
"Pragma": "no-cache",
|
|
591
|
+
},
|
|
592
|
+
"status": 200,
|
|
593
|
+
},
|
|
594
|
+
"tokenGranterAcknowledgerAcknowledgeCalls": [],
|
|
595
|
+
"tokenGranterAuthorizerAuthorizeCalls": [],
|
|
596
|
+
}
|
|
597
|
+
`);
|
|
170
598
|
});
|
|
171
599
|
|
|
172
600
|
test('should fail with a bad grant type', async () => {
|
|
173
601
|
const postOAuth2Token = await initPostOAuth2Token({
|
|
602
|
+
OAUTH2,
|
|
174
603
|
oAuth2Granters,
|
|
175
604
|
oAuth2AccessToken,
|
|
176
605
|
oAuth2RefreshToken,
|
|
@@ -181,8 +610,8 @@ describe('postOAuth2Token', () => {
|
|
|
181
610
|
try {
|
|
182
611
|
await postOAuth2Token({
|
|
183
612
|
authenticationData: {
|
|
184
|
-
|
|
185
|
-
|
|
613
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
614
|
+
scopes: ['user'],
|
|
186
615
|
} as WhookAuthenticationData,
|
|
187
616
|
body: {
|
|
188
617
|
grant_type: 'yolo',
|
|
@@ -196,19 +625,52 @@ describe('postOAuth2Token', () => {
|
|
|
196
625
|
expect({
|
|
197
626
|
errorCode: (err as YError).code,
|
|
198
627
|
errorDebug: (err as YError).debug,
|
|
628
|
+
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
629
|
+
oAuth2AccessTokenCheckCalls: oAuth2AccessToken.check.mock.calls,
|
|
630
|
+
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
631
|
+
oAuth2RefreshTokenCheckCalls: oAuth2RefreshToken.check.mock.calls,
|
|
632
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorize.mock.calls,
|
|
633
|
+
codeGranterAcknowledgerAcknowledgeCalls:
|
|
634
|
+
codeGranter.acknowledge.mock.calls,
|
|
635
|
+
codeGranterAuthenticatorAuthenticateCalls:
|
|
636
|
+
codeGranter.authenticate.mock.calls,
|
|
637
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorize.mock.calls,
|
|
638
|
+
tokenGranterAcknowledgerAcknowledgeCalls:
|
|
639
|
+
tokenGranter.acknowledge.mock.calls,
|
|
640
|
+
passwordGranterAuthenticatorAuthenticateCalls:
|
|
641
|
+
passwordGranter.authenticate.mock.calls,
|
|
642
|
+
refreshTokenGranterAuthenticatorAuthenticateCalls:
|
|
643
|
+
refreshTokenGranter.authenticate.mock.calls,
|
|
644
|
+
clientCredentialsGranterAuthenticatorAuthenticateCalls:
|
|
645
|
+
clientCredentialsGranter.authenticate.mock.calls,
|
|
646
|
+
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
199
647
|
}).toMatchInlineSnapshot(`
|
|
200
648
|
{
|
|
201
|
-
"
|
|
649
|
+
"clientCredentialsGranterAuthenticatorAuthenticateCalls": [],
|
|
650
|
+
"codeGranterAcknowledgerAcknowledgeCalls": [],
|
|
651
|
+
"codeGranterAuthenticatorAuthenticateCalls": [],
|
|
652
|
+
"codeGranterAuthorizerAuthorizeCalls": [],
|
|
653
|
+
"errorCode": "E_OAUTH2_UNKNOWN_GRANT_TYPE",
|
|
202
654
|
"errorDebug": [
|
|
203
655
|
"yolo",
|
|
204
656
|
],
|
|
657
|
+
"logCalls": [
|
|
658
|
+
[
|
|
659
|
+
"debug",
|
|
660
|
+
"👫 - OAuth2 token issuing error",
|
|
661
|
+
"E_OAUTH2_UNKNOWN_GRANT_TYPE",
|
|
662
|
+
],
|
|
663
|
+
],
|
|
664
|
+
"oAuth2AccessTokenCheckCalls": [],
|
|
665
|
+
"oAuth2AccessTokenCreateCalls": [],
|
|
666
|
+
"oAuth2RefreshTokenCheckCalls": [],
|
|
667
|
+
"oAuth2RefreshTokenCreateCalls": [],
|
|
668
|
+
"passwordGranterAuthenticatorAuthenticateCalls": [],
|
|
669
|
+
"refreshTokenGranterAuthenticatorAuthenticateCalls": [],
|
|
670
|
+
"tokenGranterAcknowledgerAcknowledgeCalls": [],
|
|
671
|
+
"tokenGranterAuthorizerAuthorizeCalls": [],
|
|
205
672
|
}
|
|
206
673
|
`);
|
|
207
|
-
expect({
|
|
208
|
-
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
209
|
-
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
210
|
-
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
211
|
-
}).toMatchSnapshot();
|
|
212
674
|
}
|
|
213
675
|
});
|
|
214
676
|
});
|