@whook/oauth2 24.1.1 → 25.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 +12 -10
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +173 -168
- package/dist/index.test.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.d.ts +39 -2
- package/dist/routes/getOAuth2Authorize.js +53 -2
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +239 -0
- package/dist/routes/getOAuth2WellKnownMetadata.js +299 -0
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -0
- package/dist/routes/getOAuth2WellKnownMetadata.test.d.ts +1 -0
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +100 -0
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -0
- package/dist/routes/postOAuth2Acknowledge.d.ts +1 -1
- package/dist/routes/postOAuth2Acknowledge.js +12 -10
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.test.js +26 -21
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/routes/postOAuth2Token.d.ts +10 -0
- package/dist/routes/postOAuth2Token.js +10 -0
- package/dist/routes/postOAuth2Token.js.map +1 -1
- package/dist/services/authCookies.d.ts +10 -9
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +5 -5
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.d.ts +31 -6
- package/dist/services/oAuth2CodeGranter.js +37 -9
- package/dist/services/oAuth2CodeGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.js +56 -20
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2Granters.d.ts +30 -26
- package/dist/services/oAuth2Granters.js +14 -0
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.d.ts +5 -5
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +5 -5
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2TokenGranter.d.ts +13 -5
- package/dist/services/oAuth2TokenGranter.js +11 -7
- package/dist/services/oAuth2TokenGranter.js.map +1 -1
- package/package.json +9 -9
- package/src/__snapshots__/index.test.ts.snap +3 -0
- package/src/index.test.ts +177 -167
- package/src/index.ts +34 -2
- package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +1 -2
- package/src/routes/getOAuth2Authorize.ts +67 -2
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +132 -0
- package/src/routes/getOAuth2WellKnownMetadata.ts +335 -0
- package/src/routes/postOAuth2Acknowledge.test.ts +26 -21
- package/src/routes/postOAuth2Acknowledge.ts +19 -18
- package/src/routes/postOAuth2Token.ts +12 -1
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +3 -0
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +13 -9
- package/src/services/oAuth2ClientCredentialsGranter.ts +5 -4
- package/src/services/oAuth2CodeGranter.test.ts +97 -30
- package/src/services/oAuth2CodeGranter.ts +89 -15
- package/src/services/oAuth2Granters.ts +60 -64
- package/src/services/oAuth2PasswordGranter.ts +5 -4
- package/src/services/oAuth2RefreshTokenGranter.ts +5 -4
- package/src/services/oAuth2TokenGranter.ts +27 -15
|
@@ -33,6 +33,16 @@ export interface OAuth2YErrorRegistry {
|
|
|
33
33
|
* Thrown when refresh_token cookie is absent and required
|
|
34
34
|
*/
|
|
35
35
|
E_REFRESH_COOKIE: [cookie: string];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when server requires PKCE
|
|
39
|
+
*/
|
|
40
|
+
E_PKCE_REQUIRED: [responseType: string];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Thrown when server does not support PKCE
|
|
44
|
+
*/
|
|
45
|
+
E_PKCE_NOT_SUPPORTED: [responseType: string];
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
export const OAUTH2_ERRORS_DESCRIPTORS: Record<
|
|
@@ -87,35 +97,35 @@ export const OAUTH2_ERRORS_DESCRIPTORS: Record<
|
|
|
87
97
|
uri: DEFAULT_ERROR_URI,
|
|
88
98
|
help: DEFAULT_HELP_URI,
|
|
89
99
|
},
|
|
100
|
+
E_PKCE_REQUIRED: {
|
|
101
|
+
code: 'invalid_request',
|
|
102
|
+
status: 400,
|
|
103
|
+
description: 'Code challenge required for this response type ($0)',
|
|
104
|
+
uri: DEFAULT_ERROR_URI,
|
|
105
|
+
help: DEFAULT_HELP_URI,
|
|
106
|
+
},
|
|
107
|
+
E_PKCE_NOT_SUPPORTED: {
|
|
108
|
+
code: 'invalid_request',
|
|
109
|
+
status: 400,
|
|
110
|
+
description: 'Code challenge not supported for this response type ($0)',
|
|
111
|
+
uri: DEFAULT_ERROR_URI,
|
|
112
|
+
help: DEFAULT_HELP_URI,
|
|
113
|
+
},
|
|
90
114
|
};
|
|
91
115
|
|
|
92
|
-
export
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
additionalParameters: Record<string, unknown>,
|
|
97
|
-
) => Promise<CODE>;
|
|
98
|
-
check: (
|
|
99
|
-
authenticationData: WhookAuthenticationData,
|
|
100
|
-
code: CODE,
|
|
101
|
-
redirectURI: string,
|
|
102
|
-
) => Promise<
|
|
103
|
-
WhookAuthenticationData & {
|
|
104
|
-
redirectURI: string;
|
|
105
|
-
} & Record<string, unknown>
|
|
106
|
-
>;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type OAuth2PasswordService<USERNAME = string, PASSWORD = string> = {
|
|
116
|
+
export interface OAuth2PasswordService<
|
|
117
|
+
USERNAME extends string = string,
|
|
118
|
+
PASSWORD extends string = string,
|
|
119
|
+
> {
|
|
110
120
|
check: (
|
|
111
121
|
authenticationData: WhookAuthenticationData,
|
|
112
122
|
username: USERNAME,
|
|
113
123
|
password: PASSWORD,
|
|
114
124
|
demandedScope: WhookAuthenticationData['scope'],
|
|
115
125
|
) => Promise<WhookAuthenticationData>;
|
|
116
|
-
}
|
|
126
|
+
}
|
|
117
127
|
|
|
118
|
-
export
|
|
128
|
+
export interface OAuth2AccessTokenService<TOKEN extends string = string> {
|
|
119
129
|
create: (
|
|
120
130
|
authenticationData: WhookAuthenticationData,
|
|
121
131
|
tokenAuthenticationData: WhookAuthenticationData,
|
|
@@ -129,9 +139,9 @@ export type OAuth2AccessTokenService<TOKEN = string> = {
|
|
|
129
139
|
token: TOKEN,
|
|
130
140
|
scope?: WhookAuthenticationData['scope'],
|
|
131
141
|
) => Promise<WhookAuthenticationData>;
|
|
132
|
-
}
|
|
142
|
+
}
|
|
133
143
|
|
|
134
|
-
export type OAuth2RefreshTokenService<TOKEN = string> =
|
|
144
|
+
export type OAuth2RefreshTokenService<TOKEN extends string = string> =
|
|
135
145
|
OAuth2AccessTokenService<TOKEN>;
|
|
136
146
|
|
|
137
147
|
export type CheckApplicationService = (context: {
|
|
@@ -146,36 +156,27 @@ export type CheckApplicationService = (context: {
|
|
|
146
156
|
redirectURI: string;
|
|
147
157
|
}>;
|
|
148
158
|
|
|
149
|
-
export type OAuth2GranterAuthorize<
|
|
150
|
-
AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<
|
|
151
|
-
string,
|
|
152
|
-
unknown
|
|
153
|
-
>,
|
|
154
|
-
> = (
|
|
159
|
+
export type OAuth2GranterAuthorize<P extends object> = (
|
|
155
160
|
context: {
|
|
156
161
|
clientId: WhookAuthenticationData['applicationId'];
|
|
157
162
|
redirectURI: string;
|
|
158
163
|
scope: WhookAuthenticationData['scope'];
|
|
159
164
|
},
|
|
160
|
-
authorizeParameters
|
|
165
|
+
authorizeParameters: P,
|
|
161
166
|
) => Promise<{
|
|
162
167
|
applicationId: WhookAuthenticationData['applicationId'];
|
|
163
168
|
redirectURI: string;
|
|
164
169
|
scope: WhookAuthenticationData['scope'];
|
|
165
170
|
}>;
|
|
166
171
|
|
|
167
|
-
export type Oauth2GranterAuthenticate<
|
|
168
|
-
|
|
169
|
-
> = (
|
|
170
|
-
grantParameters: GRANT_PARAMETERS,
|
|
172
|
+
export type Oauth2GranterAuthenticate<P extends object> = (
|
|
173
|
+
authenticateParameters: P,
|
|
171
174
|
authenticationData: WhookAuthenticationData,
|
|
172
175
|
) => Promise<WhookAuthenticationData>;
|
|
173
176
|
|
|
174
177
|
export type OAuth2GranterAcknowledge<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
unknown
|
|
178
|
-
>,
|
|
178
|
+
A extends object,
|
|
179
|
+
P extends object = Record<string, unknown>,
|
|
179
180
|
> = (
|
|
180
181
|
authenticationData: WhookAuthenticationData,
|
|
181
182
|
acknowledgeParameters: {
|
|
@@ -183,49 +184,44 @@ export type OAuth2GranterAcknowledge<
|
|
|
183
184
|
redirectURI: string;
|
|
184
185
|
scope: WhookAuthenticationData['scope'];
|
|
185
186
|
},
|
|
186
|
-
additionalParameters:
|
|
187
|
-
) => Promise<
|
|
188
|
-
WhookAuthenticationData
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<
|
|
200
|
-
string,
|
|
201
|
-
unknown
|
|
202
|
-
>,
|
|
203
|
-
GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown>,
|
|
204
|
-
> = {
|
|
187
|
+
additionalParameters: P,
|
|
188
|
+
) => Promise<{
|
|
189
|
+
authenticationData: WhookAuthenticationData;
|
|
190
|
+
redirectURI: string;
|
|
191
|
+
acknowledgedData: A;
|
|
192
|
+
}>;
|
|
193
|
+
|
|
194
|
+
export interface OAuth2GranterService<
|
|
195
|
+
T extends object = Record<string, unknown>,
|
|
196
|
+
U extends object = Record<string, unknown>,
|
|
197
|
+
V extends object = Record<string, unknown>,
|
|
198
|
+
W extends object = Record<string, unknown>,
|
|
199
|
+
> {
|
|
205
200
|
type: string;
|
|
206
201
|
authorizer?: {
|
|
207
202
|
responseType: string;
|
|
208
|
-
authorize: OAuth2GranterAuthorize<
|
|
203
|
+
authorize: OAuth2GranterAuthorize<T>;
|
|
209
204
|
};
|
|
210
205
|
acknowledger?: {
|
|
211
206
|
acknowledgmentType: string;
|
|
212
|
-
acknowledge: OAuth2GranterAcknowledge<
|
|
207
|
+
acknowledge: OAuth2GranterAcknowledge<U, V>;
|
|
213
208
|
};
|
|
214
209
|
authenticator?: {
|
|
215
210
|
grantType: string;
|
|
216
|
-
authenticate: Oauth2GranterAuthenticate<
|
|
211
|
+
authenticate: Oauth2GranterAuthenticate<W>;
|
|
217
212
|
};
|
|
218
|
-
}
|
|
213
|
+
}
|
|
219
214
|
|
|
220
|
-
export
|
|
215
|
+
export interface OAuth2Options {
|
|
221
216
|
authenticateURL: string;
|
|
222
217
|
defaultToClientScope?: boolean;
|
|
223
|
-
|
|
218
|
+
forcePKCE?: boolean;
|
|
219
|
+
}
|
|
224
220
|
|
|
225
|
-
export
|
|
221
|
+
export interface OAuth2Config {
|
|
226
222
|
OAUTH2: OAuth2Options;
|
|
227
223
|
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
228
|
-
}
|
|
224
|
+
}
|
|
229
225
|
|
|
230
226
|
export default location(
|
|
231
227
|
initializer(
|
|
@@ -8,17 +8,18 @@ import {
|
|
|
8
8
|
type CheckApplicationService,
|
|
9
9
|
} from './oAuth2Granters.js';
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export interface OAuth2PasswordGranterDependencies {
|
|
12
12
|
oAuth2Password: OAuth2PasswordService;
|
|
13
13
|
checkApplication: CheckApplicationService;
|
|
14
14
|
log?: LogService;
|
|
15
|
-
}
|
|
16
|
-
export
|
|
15
|
+
}
|
|
16
|
+
export interface OAuth2PasswordGranterParameters {
|
|
17
17
|
username: string;
|
|
18
18
|
password: string;
|
|
19
19
|
scope?: string;
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
export type OAuth2PasswordGranterService = OAuth2GranterService<
|
|
22
|
+
Record<string, unknown>,
|
|
22
23
|
Record<string, unknown>,
|
|
23
24
|
Record<string, unknown>,
|
|
24
25
|
OAuth2PasswordGranterParameters
|
|
@@ -8,16 +8,17 @@ import {
|
|
|
8
8
|
type OAuth2RefreshTokenService,
|
|
9
9
|
} from './oAuth2Granters.js';
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export interface OAuth2RefreshTokenGranterDependencies {
|
|
12
12
|
checkApplication: CheckApplicationService;
|
|
13
13
|
oAuth2RefreshToken: OAuth2RefreshTokenService;
|
|
14
14
|
log?: LogService;
|
|
15
|
-
}
|
|
16
|
-
export
|
|
15
|
+
}
|
|
16
|
+
export interface OAuth2RefreshTokenGranterParameters {
|
|
17
17
|
refreshToken: string;
|
|
18
18
|
scope?: string;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
export type OAuth2RefreshTokenGranterService = OAuth2GranterService<
|
|
21
|
+
Record<string, unknown>,
|
|
21
22
|
Record<string, unknown>,
|
|
22
23
|
Record<string, unknown>,
|
|
23
24
|
OAuth2RefreshTokenGranterParameters
|
|
@@ -5,23 +5,31 @@ import {
|
|
|
5
5
|
type OAuth2GranterService,
|
|
6
6
|
type OAuth2AccessTokenService,
|
|
7
7
|
type CheckApplicationService,
|
|
8
|
-
type OAuth2CodeService,
|
|
9
8
|
} from './oAuth2Granters.js';
|
|
9
|
+
import { type OAuth2CodeService } from './oAuth2CodeGranter.js';
|
|
10
10
|
|
|
11
11
|
export const IMPLICIT_GRANTER_TYPE = 'token';
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface OAuth2TokenGranterDependencies {
|
|
14
14
|
oAuth2Code: OAuth2CodeService;
|
|
15
15
|
checkApplication: CheckApplicationService;
|
|
16
16
|
oAuth2AccessToken: OAuth2AccessTokenService;
|
|
17
17
|
time?: TimeService;
|
|
18
18
|
log?: LogService;
|
|
19
|
-
}
|
|
20
|
-
export type
|
|
19
|
+
}
|
|
20
|
+
export type OAuth2TokenGranterAuthorizeParameters = Record<string, unknown>;
|
|
21
|
+
export interface OAuth2TokenGranterAcknowledgedData {
|
|
22
|
+
accessToken: string;
|
|
23
|
+
tokenType: 'bearer';
|
|
24
|
+
expiresIn: number;
|
|
25
|
+
}
|
|
26
|
+
export type OAuth2TokenGranterAcknowledgeParameters = Record<string, unknown>;
|
|
27
|
+
export type OAuth2TokenGranterGrantParameters = Record<string, unknown>;
|
|
21
28
|
export type OAuth2TokenGranterService = OAuth2GranterService<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
OAuth2TokenGranterAuthorizeParameters,
|
|
30
|
+
OAuth2TokenGranterAcknowledgedData,
|
|
31
|
+
OAuth2TokenGranterAcknowledgeParameters,
|
|
32
|
+
OAuth2TokenGranterGrantParameters
|
|
25
33
|
>;
|
|
26
34
|
|
|
27
35
|
export default location(autoService(initOAuth2TokenGranter), import.meta.url);
|
|
@@ -54,7 +62,7 @@ async function initOAuth2TokenGranter({
|
|
|
54
62
|
// Access Token Response:
|
|
55
63
|
// https://tools.ietf.org/html/rfc6749#section-4.2.2
|
|
56
64
|
const acknowledgeWithToken: NonNullable<
|
|
57
|
-
|
|
65
|
+
OAuth2TokenGranterService['acknowledger']
|
|
58
66
|
>['acknowledge'] = async (
|
|
59
67
|
authenticationData,
|
|
60
68
|
{ clientId, redirectURI, scope: providedScope },
|
|
@@ -80,14 +88,18 @@ async function initOAuth2TokenGranter({
|
|
|
80
88
|
);
|
|
81
89
|
|
|
82
90
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
authenticationData: {
|
|
92
|
+
...authenticationData,
|
|
93
|
+
applicationId: clientId,
|
|
94
|
+
scope: providedScope,
|
|
95
|
+
},
|
|
86
96
|
redirectURI: finalRedirectURI,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
acknowledgedData: {
|
|
98
|
+
accessToken,
|
|
99
|
+
tokenType: 'bearer',
|
|
100
|
+
expiresIn: Math.round((accessTokenExpiresAt - time()) / 1000),
|
|
101
|
+
},
|
|
102
|
+
additionalParameters,
|
|
91
103
|
};
|
|
92
104
|
};
|
|
93
105
|
|