@whook/oauth2 18.0.3 → 19.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 +36 -46
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +19 -18
- package/dist/index.test.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.d.ts +100 -0
- package/dist/{handlers → routes}/getOAuth2Authorize.js +39 -36
- package/dist/routes/getOAuth2Authorize.js.map +1 -0
- package/dist/{handlers → routes}/getOAuth2Authorize.test.js +14 -10
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -0
- package/dist/routes/postAuthLogin.d.ts +89 -0
- package/dist/{handlers → routes}/postAuthLogin.js +40 -39
- package/dist/routes/postAuthLogin.js.map +1 -0
- package/dist/routes/postAuthLogin.test.js.map +1 -0
- package/dist/routes/postAuthLogout.d.ts +28 -0
- package/dist/{handlers → routes}/postAuthLogout.js +9 -9
- package/dist/routes/postAuthLogout.js.map +1 -0
- package/dist/{handlers → routes}/postAuthLogout.test.js +1 -1
- package/dist/routes/postAuthLogout.test.js.map +1 -0
- package/dist/routes/postAuthRefresh.d.ts +94 -0
- package/dist/{handlers → routes}/postAuthRefresh.js +43 -42
- package/dist/routes/postAuthRefresh.js.map +1 -0
- package/dist/routes/postAuthRefresh.test.js.map +1 -0
- package/dist/routes/postOAuth2Acknowledge.d.ts +97 -0
- package/dist/{handlers → routes}/postOAuth2Acknowledge.js +46 -44
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -0
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -0
- package/dist/routes/postOAuth2Token.d.ts +198 -0
- package/dist/{handlers → routes}/postOAuth2Token.js +36 -34
- package/dist/routes/postOAuth2Token.js.map +1 -0
- package/dist/routes/postOAuth2Token.test.js.map +1 -0
- package/dist/services/authCookies.d.ts +3 -3
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +8 -8
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.d.ts +4 -5
- package/dist/services/oAuth2CodeGranter.js +2 -0
- package/dist/services/oAuth2CodeGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.js +2 -2
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2Granters.d.ts +25 -25
- package/dist/services/oAuth2Granters.js +1 -1
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.d.ts +4 -5
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +4 -5
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2TokenGranter.d.ts +4 -5
- package/dist/services/oAuth2TokenGranter.js +4 -0
- package/dist/services/oAuth2TokenGranter.js.map +1 -1
- package/package.json +10 -9
- package/src/__snapshots__/index.test.ts.snap +1 -0
- package/src/index.test.ts +39 -52
- package/src/index.ts +20 -20
- package/src/{handlers → routes}/getOAuth2Authorize.test.ts +18 -14
- package/src/routes/getOAuth2Authorize.ts +217 -0
- package/src/{handlers → routes}/postAuthLogin.test.ts +3 -2
- package/src/routes/postAuthLogin.ts +118 -0
- package/src/{handlers → routes}/postAuthLogout.test.ts +2 -2
- package/src/routes/postAuthLogout.ts +38 -0
- package/src/{handlers → routes}/postAuthRefresh.test.ts +3 -2
- package/src/routes/postAuthRefresh.ts +138 -0
- package/src/{handlers → routes}/postOAuth2Acknowledge.test.ts +23 -39
- package/src/{handlers → routes}/postOAuth2Acknowledge.ts +88 -96
- package/src/{handlers → routes}/postOAuth2Token.test.ts +12 -11
- package/src/{handlers → routes}/postOAuth2Token.ts +124 -129
- package/src/services/authCookies.test.ts +1 -1
- package/src/services/authCookies.ts +3 -5
- package/src/services/oAuth2ClientCredentialsGranter.ts +10 -15
- package/src/services/oAuth2CodeGranter.test.ts +12 -21
- package/src/services/oAuth2CodeGranter.ts +9 -11
- package/src/services/oAuth2Granters.ts +35 -57
- package/src/services/oAuth2PasswordGranter.ts +7 -11
- package/src/services/oAuth2RefreshTokenGranter.ts +7 -11
- package/src/services/oAuth2TokenGranter.ts +12 -12
- package/src/types.d.ts +7 -0
- package/dist/handlers/getOAuth2Authorize.d.ts +0 -27
- package/dist/handlers/getOAuth2Authorize.js.map +0 -1
- package/dist/handlers/getOAuth2Authorize.test.js.map +0 -1
- package/dist/handlers/postAuthLogin.d.ts +0 -28
- package/dist/handlers/postAuthLogin.js.map +0 -1
- package/dist/handlers/postAuthLogin.test.js.map +0 -1
- package/dist/handlers/postAuthLogout.d.ts +0 -12
- package/dist/handlers/postAuthLogout.js.map +0 -1
- package/dist/handlers/postAuthLogout.test.js.map +0 -1
- package/dist/handlers/postAuthRefresh.d.ts +0 -28
- package/dist/handlers/postAuthRefresh.js.map +0 -1
- package/dist/handlers/postAuthRefresh.test.js.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.d.ts +0 -31
- package/dist/handlers/postOAuth2Acknowledge.js.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +0 -1
- package/dist/handlers/postOAuth2Token.d.ts +0 -36
- package/dist/handlers/postOAuth2Token.js.map +0 -1
- package/dist/handlers/postOAuth2Token.test.js.map +0 -1
- package/src/handlers/getOAuth2Authorize.ts +0 -214
- package/src/handlers/postAuthLogin.ts +0 -123
- package/src/handlers/postAuthLogout.ts +0 -38
- package/src/handlers/postAuthRefresh.ts +0 -143
- /package/dist/{handlers → routes}/getOAuth2Authorize.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthLogin.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthLogin.test.js +0 -0
- /package/dist/{handlers → routes}/postAuthLogout.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthRefresh.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthRefresh.test.js +0 -0
- /package/dist/{handlers → routes}/postOAuth2Acknowledge.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postOAuth2Acknowledge.test.js +0 -0
- /package/dist/{handlers → routes}/postOAuth2Token.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postOAuth2Token.test.js +0 -0
- /package/src/{handlers → routes}/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -0
- /package/src/{handlers → routes}/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -0
- /package/src/{handlers → routes}/__snapshots__/postOAuth2Token.test.ts.snap +0 -0
|
@@ -3,16 +3,11 @@ import initPostOAuth2Acknowledge from './postOAuth2Acknowledge.js';
|
|
|
3
3
|
import { YError } from 'yerror';
|
|
4
4
|
import { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';
|
|
5
5
|
import { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters.js';
|
|
6
|
-
import type
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
9
|
-
import type
|
|
10
|
-
import type
|
|
11
|
-
import type { OAuth2TokenGranterService } from '../services/oAuth2TokenGranter.js';
|
|
12
|
-
|
|
13
|
-
type CustomAuthenticationData = BaseAuthenticationData & {
|
|
14
|
-
userId: string;
|
|
15
|
-
};
|
|
6
|
+
import { type CheckApplicationService } from '../services/oAuth2Granters.js';
|
|
7
|
+
import { type LogService } from 'common-services';
|
|
8
|
+
import { type OAuth2GranterService } from '../services/oAuth2Granters.js';
|
|
9
|
+
import { type OAuth2CodeGranterService } from '../services/oAuth2CodeGranter.js';
|
|
10
|
+
import { type OAuth2TokenGranterService } from '../services/oAuth2TokenGranter.js';
|
|
16
11
|
|
|
17
12
|
describe('postOAuth2Acknowledge', () => {
|
|
18
13
|
const ERRORS_DESCRIPTORS = {
|
|
@@ -27,27 +22,21 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
27
22
|
responseType: 'code',
|
|
28
23
|
authorize:
|
|
29
24
|
jest.fn<
|
|
30
|
-
NonNullable<
|
|
31
|
-
OAuth2CodeGranterService<CustomAuthenticationData>['authorizer']
|
|
32
|
-
>['authorize']
|
|
25
|
+
NonNullable<OAuth2CodeGranterService['authorizer']>['authorize']
|
|
33
26
|
>(),
|
|
34
27
|
},
|
|
35
28
|
acknowledger: {
|
|
36
29
|
acknowledgmentType: 'code',
|
|
37
30
|
acknowledge:
|
|
38
31
|
jest.fn<
|
|
39
|
-
NonNullable<
|
|
40
|
-
OAuth2CodeGranterService<CustomAuthenticationData>['acknowledger']
|
|
41
|
-
>['acknowledge']
|
|
32
|
+
NonNullable<OAuth2CodeGranterService['acknowledger']>['acknowledge']
|
|
42
33
|
>(),
|
|
43
34
|
},
|
|
44
35
|
authenticator: {
|
|
45
36
|
grantType: 'authorization_code',
|
|
46
37
|
authenticate:
|
|
47
38
|
jest.fn<
|
|
48
|
-
NonNullable<
|
|
49
|
-
OAuth2CodeGranterService<CustomAuthenticationData>['authenticator']
|
|
50
|
-
>['authenticate']
|
|
39
|
+
NonNullable<OAuth2CodeGranterService['authenticator']>['authenticate']
|
|
51
40
|
>(),
|
|
52
41
|
},
|
|
53
42
|
};
|
|
@@ -58,7 +47,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
58
47
|
authorize:
|
|
59
48
|
jest.fn<
|
|
60
49
|
NonNullable<
|
|
61
|
-
OAuth2TokenGranterService
|
|
50
|
+
OAuth2TokenGranterService['authenticator']
|
|
62
51
|
>['authenticate']
|
|
63
52
|
>(),
|
|
64
53
|
},
|
|
@@ -66,9 +55,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
66
55
|
acknowledgmentType: 'token',
|
|
67
56
|
acknowledge:
|
|
68
57
|
jest.fn<
|
|
69
|
-
NonNullable<
|
|
70
|
-
OAuth2TokenGranterService<CustomAuthenticationData>['acknowledger']
|
|
71
|
-
>['acknowledge']
|
|
58
|
+
NonNullable<OAuth2TokenGranterService['acknowledger']>['acknowledge']
|
|
72
59
|
>(),
|
|
73
60
|
},
|
|
74
61
|
};
|
|
@@ -78,8 +65,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
78
65
|
] as unknown as OAuth2GranterService<
|
|
79
66
|
Record<string, unknown>,
|
|
80
67
|
Record<string, unknown>,
|
|
81
|
-
Record<string, unknown
|
|
82
|
-
CustomAuthenticationData
|
|
68
|
+
Record<string, unknown>
|
|
83
69
|
>[];
|
|
84
70
|
|
|
85
71
|
beforeEach(() => {
|
|
@@ -110,13 +96,12 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
110
96
|
userId: '1',
|
|
111
97
|
});
|
|
112
98
|
|
|
113
|
-
const postOAuth2Acknowledge =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
99
|
+
const postOAuth2Acknowledge = await initPostOAuth2Acknowledge({
|
|
100
|
+
ERRORS_DESCRIPTORS,
|
|
101
|
+
oAuth2Granters,
|
|
102
|
+
checkApplication,
|
|
103
|
+
log,
|
|
104
|
+
});
|
|
120
105
|
const response = await postOAuth2Acknowledge({
|
|
121
106
|
authenticationData: {
|
|
122
107
|
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
@@ -171,13 +156,12 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
171
156
|
mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),
|
|
172
157
|
);
|
|
173
158
|
|
|
174
|
-
const postOAuth2Acknowledge =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
159
|
+
const postOAuth2Acknowledge = await initPostOAuth2Acknowledge({
|
|
160
|
+
ERRORS_DESCRIPTORS,
|
|
161
|
+
oAuth2Granters,
|
|
162
|
+
checkApplication,
|
|
163
|
+
log,
|
|
164
|
+
});
|
|
181
165
|
const response = await postOAuth2Acknowledge({
|
|
182
166
|
authenticationData: {
|
|
183
167
|
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { autoService, location } from 'knifecycle';
|
|
2
2
|
import { printStackTrace, YError } from 'yerror';
|
|
3
3
|
import { setURLError } from './getOAuth2Authorize.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
WhookErrorsDescriptors,
|
|
4
|
+
import {
|
|
5
|
+
type WhookRouteDefinition,
|
|
6
|
+
type WhookErrorsDescriptors,
|
|
7
7
|
} from '@whook/whook';
|
|
8
|
-
import
|
|
9
|
-
CheckApplicationService,
|
|
10
|
-
OAuth2GranterService,
|
|
8
|
+
import {
|
|
9
|
+
type CheckApplicationService,
|
|
10
|
+
type OAuth2GranterService,
|
|
11
11
|
} from '../services/oAuth2Granters.js';
|
|
12
|
-
import type
|
|
13
|
-
import type
|
|
12
|
+
import { type LogService } from 'common-services';
|
|
13
|
+
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
14
14
|
|
|
15
15
|
/* Architecture Note #2: OAuth2 acknowledge
|
|
16
16
|
This endpoint is to be used by the authentication SSR frontend
|
|
17
17
|
to acknowlege that the user accepted the client request in it.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
export const definition
|
|
20
|
+
export const definition = {
|
|
21
21
|
method: 'post',
|
|
22
22
|
path: '/oauth2/acknowledge',
|
|
23
|
+
config: {
|
|
24
|
+
private: true,
|
|
25
|
+
},
|
|
23
26
|
operation: {
|
|
24
27
|
operationId: 'postOAuth2Acknowledge',
|
|
25
28
|
summary: `Implements the logic that allow the authentication frontend
|
|
26
29
|
to get the [Redirection Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1.2).`,
|
|
27
30
|
tags: ['oauth2'],
|
|
28
|
-
'x-whook': {
|
|
29
|
-
private: true,
|
|
30
|
-
},
|
|
31
31
|
requestBody: {
|
|
32
32
|
required: true,
|
|
33
33
|
content: {
|
|
@@ -93,23 +93,20 @@ export const definition: WhookAPIHandlerDefinition = {
|
|
|
93
93
|
},
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
|
-
};
|
|
96
|
+
} as const satisfies WhookRouteDefinition;
|
|
97
97
|
|
|
98
|
-
export type HandlerDependencies
|
|
99
|
-
AUTHENTICATION_DATA extends BaseAuthenticationData<string, string>,
|
|
100
|
-
> = {
|
|
98
|
+
export type HandlerDependencies = {
|
|
101
99
|
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
102
100
|
oAuth2Granters: OAuth2GranterService<
|
|
103
101
|
Record<string, unknown>,
|
|
104
102
|
Record<string, unknown>,
|
|
105
|
-
Record<string, unknown
|
|
106
|
-
AUTHENTICATION_DATA
|
|
103
|
+
Record<string, unknown>
|
|
107
104
|
>[];
|
|
108
105
|
checkApplication: CheckApplicationService;
|
|
109
106
|
log: LogService;
|
|
110
107
|
};
|
|
111
|
-
type HandlerParameters
|
|
112
|
-
authenticationData:
|
|
108
|
+
type HandlerParameters = {
|
|
109
|
+
authenticationData: WhookAuthenticationData;
|
|
113
110
|
body: {
|
|
114
111
|
responseType: string;
|
|
115
112
|
clientId: string;
|
|
@@ -122,26 +119,21 @@ type HandlerParameters<AUTHENTICATION_DATA> = {
|
|
|
122
119
|
};
|
|
123
120
|
|
|
124
121
|
export default location(
|
|
125
|
-
|
|
122
|
+
autoService(initPostOAuth2Acknowledge),
|
|
126
123
|
import.meta.url,
|
|
127
|
-
) as unknown as
|
|
128
|
-
|
|
129
|
-
>(
|
|
130
|
-
dependencies: HandlerDependencies<AUTHENTICATION_DATA>,
|
|
124
|
+
) as unknown as (
|
|
125
|
+
dependencies: HandlerDependencies,
|
|
131
126
|
) => (
|
|
132
|
-
parameters: HandlerParameters
|
|
133
|
-
) => ReturnType<typeof
|
|
127
|
+
parameters: HandlerParameters,
|
|
128
|
+
) => ReturnType<typeof initPostOAuth2Acknowledge>;
|
|
134
129
|
|
|
135
|
-
async function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
log,
|
|
143
|
-
}: HandlerDependencies<AUTHENTICATION_DATA>,
|
|
144
|
-
{
|
|
130
|
+
async function initPostOAuth2Acknowledge({
|
|
131
|
+
ERRORS_DESCRIPTORS,
|
|
132
|
+
oAuth2Granters,
|
|
133
|
+
checkApplication,
|
|
134
|
+
log,
|
|
135
|
+
}: HandlerDependencies) {
|
|
136
|
+
return async ({
|
|
145
137
|
authenticationData,
|
|
146
138
|
body: {
|
|
147
139
|
responseType,
|
|
@@ -152,73 +144,73 @@ async function postOAuth2Acknowledge<
|
|
|
152
144
|
acknowledged = false,
|
|
153
145
|
...additionalParameters
|
|
154
146
|
},
|
|
155
|
-
}: HandlerParameters
|
|
156
|
-
) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
147
|
+
}: HandlerParameters) => {
|
|
148
|
+
if (!authenticationData) {
|
|
149
|
+
throw new YError('E_UNAUTHORIZED');
|
|
150
|
+
}
|
|
160
151
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
// Here we check the applicationId has the right to authenticate a user
|
|
153
|
+
// with the special type 'root'
|
|
154
|
+
await checkApplication({
|
|
155
|
+
applicationId: authenticationData.applicationId,
|
|
156
|
+
type: 'root',
|
|
157
|
+
scope: '',
|
|
158
|
+
});
|
|
168
159
|
|
|
169
|
-
|
|
160
|
+
const url = new URL(redirectURI);
|
|
170
161
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
162
|
+
try {
|
|
163
|
+
if (!acknowledged) {
|
|
164
|
+
throw new YError('E_ACCESS_DENIED', clientId);
|
|
165
|
+
}
|
|
175
166
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
167
|
+
const granter = oAuth2Granters.find(
|
|
168
|
+
(granter) =>
|
|
169
|
+
granter.acknowledger &&
|
|
170
|
+
granter.acknowledger.acknowledgmentType === responseType,
|
|
171
|
+
);
|
|
181
172
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
173
|
+
if (!granter || !granter.acknowledger) {
|
|
174
|
+
throw new YError('E_UNKNOWN_ACKNOWLEDGOR_TYPE', responseType);
|
|
175
|
+
}
|
|
185
176
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
177
|
+
const { applicationId, scope, ...additionalProperties } =
|
|
178
|
+
await granter.acknowledger.acknowledge(
|
|
179
|
+
authenticationData,
|
|
180
|
+
{
|
|
181
|
+
clientId,
|
|
182
|
+
redirectURI,
|
|
183
|
+
scope: demandedScope,
|
|
184
|
+
},
|
|
185
|
+
additionalParameters,
|
|
186
|
+
);
|
|
196
187
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
188
|
+
url.searchParams.set('client_id', applicationId);
|
|
189
|
+
url.searchParams.set('scope', scope);
|
|
190
|
+
url.searchParams.set('state', state);
|
|
191
|
+
Object.keys(additionalProperties).forEach((key) =>
|
|
192
|
+
url.searchParams.set(
|
|
193
|
+
snakeCase(key),
|
|
194
|
+
additionalProperties[key] as unknown as string,
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
} catch (err) {
|
|
198
|
+
log('debug', '👫 - OAuth2 acknowledge error', (err as YError).code);
|
|
199
|
+
log('debug-stack', printStackTrace(err as Error));
|
|
209
200
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
201
|
+
setURLError(
|
|
202
|
+
url,
|
|
203
|
+
err as YError,
|
|
204
|
+
ERRORS_DESCRIPTORS[(err as YError).code] || ERRORS_DESCRIPTORS.E_OAUTH2,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
216
207
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
return {
|
|
209
|
+
status: 302,
|
|
210
|
+
headers: {
|
|
211
|
+
location: url.href,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
222
214
|
};
|
|
223
215
|
}
|
|
224
216
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { describe, test, beforeEach, jest, expect } from '@jest/globals';
|
|
2
2
|
import initPostOAuth2Token from './postOAuth2Token.js';
|
|
3
3
|
import { YError } from 'yerror';
|
|
4
|
-
import type
|
|
5
|
-
import
|
|
6
|
-
OAuth2GranterService,
|
|
7
|
-
OAuth2AccessTokenService,
|
|
8
|
-
OAuth2RefreshTokenService,
|
|
4
|
+
import { type LogService, type TimeService } from 'common-services';
|
|
5
|
+
import {
|
|
6
|
+
type OAuth2GranterService,
|
|
7
|
+
type OAuth2AccessTokenService,
|
|
8
|
+
type OAuth2RefreshTokenService,
|
|
9
9
|
} from '../index.js';
|
|
10
|
-
import type
|
|
11
|
-
import type
|
|
12
|
-
import type
|
|
13
|
-
import type
|
|
10
|
+
import { type OAuth2CodeGranterService } from '../services/oAuth2CodeGranter.js';
|
|
11
|
+
import { type OAuth2TokenGranterService } from '../services/oAuth2TokenGranter.js';
|
|
12
|
+
import { type OAuth2PasswordGranterService } from '../services/oAuth2PasswordGranter.js';
|
|
13
|
+
import { type OAuth2RefreshTokenGranterService } from '../services/oAuth2RefreshTokenGranter.js';
|
|
14
|
+
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
14
15
|
|
|
15
16
|
describe('postOAuth2Token', () => {
|
|
16
17
|
const log = jest.fn<LogService>();
|
|
@@ -152,7 +153,7 @@ describe('postOAuth2Token', () => {
|
|
|
152
153
|
authenticationData: {
|
|
153
154
|
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
154
155
|
scope: 'user',
|
|
155
|
-
},
|
|
156
|
+
} as WhookAuthenticationData,
|
|
156
157
|
body: {
|
|
157
158
|
grant_type: 'authorization_code',
|
|
158
159
|
code: '007',
|
|
@@ -182,7 +183,7 @@ describe('postOAuth2Token', () => {
|
|
|
182
183
|
authenticationData: {
|
|
183
184
|
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
184
185
|
scope: 'user',
|
|
185
|
-
},
|
|
186
|
+
} as WhookAuthenticationData,
|
|
186
187
|
body: {
|
|
187
188
|
grant_type: 'yolo',
|
|
188
189
|
code: '007',
|