@cloudflare/workers-oauth-provider 0.0.13 → 0.2.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 +65 -46
- package/dist/oauth-provider.d.ts +563 -507
- package/dist/oauth-provider.js +1549 -1547
- package/package.json +11 -11
package/dist/oauth-provider.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { WorkerEntrypoint } from
|
|
1
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
2
|
+
|
|
3
|
+
//#region src/oauth-provider.d.ts
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Aliases for either type of Handler that makes .fetch required
|
|
@@ -13,574 +15,628 @@ type WorkerEntrypointWithFetch = WorkerEntrypoint & Pick<Required<WorkerEntrypoi
|
|
|
13
15
|
* Allows updating the props stored in both the access token and the grant.
|
|
14
16
|
*/
|
|
15
17
|
interface TokenExchangeCallbackResult {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
18
|
+
/**
|
|
19
|
+
* New props to be stored specifically with the access token.
|
|
20
|
+
* If not provided but newProps is, the access token will use newProps.
|
|
21
|
+
* If neither is provided, the original props will be used.
|
|
22
|
+
*/
|
|
23
|
+
accessTokenProps?: any;
|
|
24
|
+
/**
|
|
25
|
+
* New props to replace the props stored in the grant itself.
|
|
26
|
+
* These props will be used for all future token refreshes.
|
|
27
|
+
* If accessTokenProps is not provided, these props will also be used for the current access token.
|
|
28
|
+
* If not provided, the original props will be used.
|
|
29
|
+
*/
|
|
30
|
+
newProps?: any;
|
|
31
|
+
/**
|
|
32
|
+
* Override the default access token TTL (time-to-live) for this specific token.
|
|
33
|
+
* This is especially useful when the application is also an OAuth client to another service
|
|
34
|
+
* and wants to match its access token TTL to the upstream access token TTL.
|
|
35
|
+
* Value should be in seconds.
|
|
36
|
+
*/
|
|
37
|
+
accessTokenTTL?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Override the default refresh token TTL (time-to-live) for this specific grant.
|
|
40
|
+
* Value should be in seconds.
|
|
41
|
+
* Note: This is only honored during authorization code exchange. If returned during
|
|
42
|
+
* refresh token exchange, it will be ignored.
|
|
43
|
+
*/
|
|
44
|
+
refreshTokenTTL?: number;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Options for token exchange callback functions
|
|
46
48
|
*/
|
|
47
49
|
interface TokenExchangeCallbackOptions {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The type of grant being processed.
|
|
52
|
+
* 'authorization_code' for initial code exchange,
|
|
53
|
+
* 'refresh_token' for refresh token exchange.
|
|
54
|
+
*/
|
|
55
|
+
grantType: 'authorization_code' | 'refresh_token';
|
|
56
|
+
/**
|
|
57
|
+
* Client that received this grant
|
|
58
|
+
*/
|
|
59
|
+
clientId: string;
|
|
60
|
+
/**
|
|
61
|
+
* User who authorized this grant
|
|
62
|
+
*/
|
|
63
|
+
userId: string;
|
|
64
|
+
/**
|
|
65
|
+
* List of scopes that were granted
|
|
66
|
+
*/
|
|
67
|
+
scope: string[];
|
|
68
|
+
/**
|
|
69
|
+
* Application-specific properties currently associated with this grant
|
|
70
|
+
*/
|
|
71
|
+
props: any;
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* Input parameters for the resolveExternalToken callback function
|
|
73
75
|
*/
|
|
74
76
|
interface ResolveExternalTokenInput {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The token string that was provided in the Authorization header
|
|
79
|
+
*/
|
|
80
|
+
token: string;
|
|
81
|
+
/**
|
|
82
|
+
* The original HTTP request
|
|
83
|
+
*/
|
|
84
|
+
request: Request;
|
|
85
|
+
/**
|
|
86
|
+
* Cloudflare Worker environment variables
|
|
87
|
+
*/
|
|
88
|
+
env: any;
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
91
|
* Result returned from the resolveExternalToken callback function
|
|
90
92
|
*/
|
|
91
93
|
interface ResolveExternalTokenResult {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Application-specific properties that will be passed to the API handlers
|
|
96
|
+
* These properties are set in the execution context (ctx.props) when the external token is validated
|
|
97
|
+
*/
|
|
98
|
+
props: any;
|
|
99
|
+
/**
|
|
100
|
+
* Audience claim from the external token (RFC 7519 Section 4.1.3)
|
|
101
|
+
* If provided, will be validated against the resource server identity
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
audience?: string | string[];
|
|
97
105
|
}
|
|
98
106
|
interface OAuthProviderOptions {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
107
|
+
/**
|
|
108
|
+
* URL(s) for API routes. Requests with URLs starting with any of these prefixes
|
|
109
|
+
* will be treated as API requests and require a valid access token.
|
|
110
|
+
* Can be a single route or an array of routes. Each route can be a full URL or just a path.
|
|
111
|
+
*
|
|
112
|
+
* Used with `apiHandler` for the single-handler configuration. This is incompatible with
|
|
113
|
+
* the `apiHandlers` property. You must use either `apiRoute` + `apiHandler` OR `apiHandlers`, not both.
|
|
114
|
+
*/
|
|
115
|
+
apiRoute?: string | string[];
|
|
116
|
+
/**
|
|
117
|
+
* Handler for API requests that have a valid access token.
|
|
118
|
+
* This handler will receive the authenticated user properties in ctx.props.
|
|
119
|
+
* Can be either an ExportedHandler object with a fetch method or a class extending WorkerEntrypoint.
|
|
120
|
+
*
|
|
121
|
+
* Used with `apiRoute` for the single-handler configuration. This is incompatible with
|
|
122
|
+
* the `apiHandlers` property. You must use either `apiRoute` + `apiHandler` OR `apiHandlers`, not both.
|
|
123
|
+
*/
|
|
124
|
+
apiHandler?: ExportedHandlerWithFetch | (new (ctx: ExecutionContext, env: any) => WorkerEntrypointWithFetch);
|
|
125
|
+
/**
|
|
126
|
+
* Map of API routes to their corresponding handlers for the multi-handler configuration.
|
|
127
|
+
* The keys are the API routes (strings only, not arrays), and the values are the handlers.
|
|
128
|
+
* Each route can be a full URL or just a path, and each handler can be either an ExportedHandler
|
|
129
|
+
* object with a fetch method or a class extending WorkerEntrypoint.
|
|
130
|
+
*
|
|
131
|
+
* This is incompatible with the `apiRoute` and `apiHandler` properties. You must use either
|
|
132
|
+
* `apiRoute` + `apiHandler` (single-handler configuration) OR `apiHandlers` (multi-handler
|
|
133
|
+
* configuration), not both.
|
|
134
|
+
*/
|
|
135
|
+
apiHandlers?: Record<string, ExportedHandlerWithFetch | (new (ctx: ExecutionContext, env: any) => WorkerEntrypointWithFetch)>;
|
|
136
|
+
/**
|
|
137
|
+
* Handler for all non-API requests or API requests without a valid token.
|
|
138
|
+
* Can be either an ExportedHandler object with a fetch method or a class extending WorkerEntrypoint.
|
|
139
|
+
*/
|
|
140
|
+
defaultHandler: ExportedHandler | (new (ctx: ExecutionContext, env: any) => WorkerEntrypointWithFetch);
|
|
141
|
+
/**
|
|
142
|
+
* URL of the OAuth authorization endpoint where users can grant permissions.
|
|
143
|
+
* This URL is used in OAuth metadata and is not handled by the provider itself.
|
|
144
|
+
*/
|
|
145
|
+
authorizeEndpoint: string;
|
|
146
|
+
/**
|
|
147
|
+
* URL of the token endpoint which the provider will implement.
|
|
148
|
+
* This endpoint handles token issuance, refresh, and revocation.
|
|
149
|
+
*/
|
|
150
|
+
tokenEndpoint: string;
|
|
151
|
+
/**
|
|
152
|
+
* Optional URL for the client registration endpoint.
|
|
153
|
+
* If provided, the provider will implement dynamic client registration.
|
|
154
|
+
*/
|
|
155
|
+
clientRegistrationEndpoint?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Time-to-live for access tokens in seconds.
|
|
158
|
+
* Defaults to 1 hour (3600 seconds) if not specified.
|
|
159
|
+
*/
|
|
160
|
+
accessTokenTTL?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Time-to-live for refresh tokens in seconds.
|
|
163
|
+
* If not specified, refresh tokens do not expire.
|
|
164
|
+
* For example: 3600 = 1 hour, 2592000 = 30 days
|
|
165
|
+
*/
|
|
166
|
+
refreshTokenTTL?: number;
|
|
167
|
+
/**
|
|
168
|
+
* List of scopes supported by this OAuth provider.
|
|
169
|
+
* If not provided, the 'scopes_supported' field will be omitted from the OAuth metadata.
|
|
170
|
+
*/
|
|
171
|
+
scopesSupported?: string[];
|
|
172
|
+
/**
|
|
173
|
+
* Controls whether the OAuth implicit flow is allowed.
|
|
174
|
+
* This flow is discouraged in OAuth 2.1 due to security concerns.
|
|
175
|
+
* Defaults to false.
|
|
176
|
+
*/
|
|
177
|
+
allowImplicitFlow?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Controls whether public clients (clients without a secret, like SPAs) can register via the
|
|
180
|
+
* dynamic client registration endpoint. When true, only confidential clients can register.
|
|
181
|
+
* Note: Creating public clients via the OAuthHelpers.createClient() method is always allowed.
|
|
182
|
+
* Defaults to false.
|
|
183
|
+
*/
|
|
184
|
+
disallowPublicClientRegistration?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Optional callback function that is called during token exchange.
|
|
187
|
+
* This allows updating the props stored in both the access token and the grant.
|
|
188
|
+
* For example, if the application itself is also a client to some other OAuth API,
|
|
189
|
+
* it may want to perform the equivalent upstream token exchange, and store the result in the props.
|
|
190
|
+
*
|
|
191
|
+
* The callback can return new props values that will be stored with the token or grant.
|
|
192
|
+
* If the callback returns nothing or undefined for a props field, the original props will be used.
|
|
193
|
+
*/
|
|
194
|
+
tokenExchangeCallback?: (options: TokenExchangeCallbackOptions) => Promise<TokenExchangeCallbackResult | void> | TokenExchangeCallbackResult | void;
|
|
195
|
+
/**
|
|
196
|
+
* Optional callback function that is called when a provided token was not found in the internal KV.
|
|
197
|
+
* This allows authentication through external OAuth servers.
|
|
198
|
+
* For example, if a request includes an authenticated token from a different OAuth authentication server,
|
|
199
|
+
* the callback can be used to authenticate it and set the context props through it.
|
|
200
|
+
*
|
|
201
|
+
* The callback can optionally return props values that will passed-through to the apiHandlers.
|
|
202
|
+
* The callback can return `null` to signal resolution failure.
|
|
203
|
+
*/
|
|
204
|
+
resolveExternalToken?: (input: ResolveExternalTokenInput) => Promise<ResolveExternalTokenResult | null>;
|
|
205
|
+
/**
|
|
206
|
+
* Optional callback function that is called whenever the OAuthProvider returns an error response
|
|
207
|
+
* This allows the client to emit notifications or perform other actions when an error occurs.
|
|
208
|
+
*
|
|
209
|
+
* If the function returns a Response, that will be used in place of the OAuthProvider's default one.
|
|
210
|
+
*/
|
|
211
|
+
onError?: (error: {
|
|
212
|
+
code: string;
|
|
213
|
+
description: string;
|
|
214
|
+
status: number;
|
|
215
|
+
headers: Record<string, string>;
|
|
216
|
+
}) => Response | void;
|
|
209
217
|
}
|
|
210
218
|
/**
|
|
211
219
|
* Helper methods for OAuth operations provided to handler functions
|
|
212
220
|
*/
|
|
213
221
|
interface OAuthHelpers {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Parses an OAuth authorization request from the HTTP request
|
|
224
|
+
* @param request - The HTTP request containing OAuth parameters
|
|
225
|
+
* @returns The parsed authorization request parameters
|
|
226
|
+
*/
|
|
227
|
+
parseAuthRequest(request: Request): Promise<AuthRequest>;
|
|
228
|
+
/**
|
|
229
|
+
* Looks up a client by its client ID
|
|
230
|
+
* @param clientId - The client ID to look up
|
|
231
|
+
* @returns A Promise resolving to the client info, or null if not found
|
|
232
|
+
*/
|
|
233
|
+
lookupClient(clientId: string): Promise<ClientInfo | null>;
|
|
234
|
+
/**
|
|
235
|
+
* Completes an authorization request by creating a grant and authorization code
|
|
236
|
+
* @param options - Options specifying the grant details
|
|
237
|
+
* @returns A Promise resolving to an object containing the redirect URL
|
|
238
|
+
*/
|
|
239
|
+
completeAuthorization(options: CompleteAuthorizationOptions): Promise<{
|
|
240
|
+
redirectTo: string;
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Creates a new OAuth client
|
|
244
|
+
* @param clientInfo - Partial client information to create the client with
|
|
245
|
+
* @returns A Promise resolving to the created client info
|
|
246
|
+
*/
|
|
247
|
+
createClient(clientInfo: Partial<ClientInfo>): Promise<ClientInfo>;
|
|
248
|
+
/**
|
|
249
|
+
* Lists all registered OAuth clients with pagination support
|
|
250
|
+
* @param options - Optional pagination parameters (limit and cursor)
|
|
251
|
+
* @returns A Promise resolving to the list result with items and optional cursor
|
|
252
|
+
*/
|
|
253
|
+
listClients(options?: ListOptions): Promise<ListResult<ClientInfo>>;
|
|
254
|
+
/**
|
|
255
|
+
* Updates an existing OAuth client
|
|
256
|
+
* @param clientId - The ID of the client to update
|
|
257
|
+
* @param updates - Partial client information with fields to update
|
|
258
|
+
* @returns A Promise resolving to the updated client info, or null if not found
|
|
259
|
+
*/
|
|
260
|
+
updateClient(clientId: string, updates: Partial<ClientInfo>): Promise<ClientInfo | null>;
|
|
261
|
+
/**
|
|
262
|
+
* Deletes an OAuth client
|
|
263
|
+
* @param clientId - The ID of the client to delete
|
|
264
|
+
* @returns A Promise resolving when the deletion is confirmed.
|
|
265
|
+
*/
|
|
266
|
+
deleteClient(clientId: string): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Lists all authorization grants for a specific user with pagination support
|
|
269
|
+
* Returns a summary of each grant without sensitive information
|
|
270
|
+
* @param userId - The ID of the user whose grants to list
|
|
271
|
+
* @param options - Optional pagination parameters (limit and cursor)
|
|
272
|
+
* @returns A Promise resolving to the list result with grant summaries and optional cursor
|
|
273
|
+
*/
|
|
274
|
+
listUserGrants(userId: string, options?: ListOptions): Promise<ListResult<GrantSummary>>;
|
|
275
|
+
/**
|
|
276
|
+
* Revokes an authorization grant
|
|
277
|
+
* @param grantId - The ID of the grant to revoke
|
|
278
|
+
* @param userId - The ID of the user who owns the grant
|
|
279
|
+
* @returns A Promise resolving when the revocation is confirmed.
|
|
280
|
+
*/
|
|
281
|
+
revokeGrant(grantId: string, userId: string): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Decodes a token and returns token data with decrypted props
|
|
284
|
+
* @param token - The token
|
|
285
|
+
* @returns Promise resolving to token data with decrypted props, or null if token is invalid
|
|
286
|
+
*/
|
|
287
|
+
unwrapToken<T = any>(token: string): Promise<TokenSummary<T> | null>;
|
|
274
288
|
}
|
|
275
289
|
/**
|
|
276
290
|
* Parsed OAuth authorization request parameters
|
|
277
291
|
*/
|
|
278
292
|
interface AuthRequest {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
293
|
+
/**
|
|
294
|
+
* OAuth response type (e.g., "code" for authorization code flow)
|
|
295
|
+
*/
|
|
296
|
+
responseType: string;
|
|
297
|
+
/**
|
|
298
|
+
* Client identifier for the OAuth client
|
|
299
|
+
*/
|
|
300
|
+
clientId: string;
|
|
301
|
+
/**
|
|
302
|
+
* URL to redirect to after authorization
|
|
303
|
+
*/
|
|
304
|
+
redirectUri: string;
|
|
305
|
+
/**
|
|
306
|
+
* Array of requested permission scopes
|
|
307
|
+
*/
|
|
308
|
+
scope: string[];
|
|
309
|
+
/**
|
|
310
|
+
* Client state value to be returned in the redirect
|
|
311
|
+
*/
|
|
312
|
+
state: string;
|
|
313
|
+
/**
|
|
314
|
+
* PKCE code challenge (RFC 7636)
|
|
315
|
+
*/
|
|
316
|
+
codeChallenge?: string;
|
|
317
|
+
/**
|
|
318
|
+
* PKCE code challenge method (plain or S256)
|
|
319
|
+
*/
|
|
320
|
+
codeChallengeMethod?: string;
|
|
321
|
+
/**
|
|
322
|
+
* Resource parameter indicating target resource(s) (RFC 8707)
|
|
323
|
+
*/
|
|
324
|
+
resource?: string | string[];
|
|
307
325
|
}
|
|
308
326
|
/**
|
|
309
327
|
* OAuth client registration information
|
|
310
328
|
*/
|
|
311
329
|
interface ClientInfo {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Unique identifier for the client
|
|
332
|
+
*/
|
|
333
|
+
clientId: string;
|
|
334
|
+
/**
|
|
335
|
+
* Secret used to authenticate the client (stored as a hash)
|
|
336
|
+
* Only present for confidential clients; undefined for public clients.
|
|
337
|
+
*/
|
|
338
|
+
clientSecret?: string;
|
|
339
|
+
/**
|
|
340
|
+
* List of allowed redirect URIs for the client
|
|
341
|
+
*/
|
|
342
|
+
redirectUris: string[];
|
|
343
|
+
/**
|
|
344
|
+
* Human-readable name of the client application
|
|
345
|
+
*/
|
|
346
|
+
clientName?: string;
|
|
347
|
+
/**
|
|
348
|
+
* URL to the client's logo
|
|
349
|
+
*/
|
|
350
|
+
logoUri?: string;
|
|
351
|
+
/**
|
|
352
|
+
* URL to the client's homepage
|
|
353
|
+
*/
|
|
354
|
+
clientUri?: string;
|
|
355
|
+
/**
|
|
356
|
+
* URL to the client's privacy policy
|
|
357
|
+
*/
|
|
358
|
+
policyUri?: string;
|
|
359
|
+
/**
|
|
360
|
+
* URL to the client's terms of service
|
|
361
|
+
*/
|
|
362
|
+
tosUri?: string;
|
|
363
|
+
/**
|
|
364
|
+
* URL to the client's JSON Web Key Set for validating signatures
|
|
365
|
+
*/
|
|
366
|
+
jwksUri?: string;
|
|
367
|
+
/**
|
|
368
|
+
* List of email addresses for contacting the client developers
|
|
369
|
+
*/
|
|
370
|
+
contacts?: string[];
|
|
371
|
+
/**
|
|
372
|
+
* List of grant types the client supports
|
|
373
|
+
*/
|
|
374
|
+
grantTypes?: string[];
|
|
375
|
+
/**
|
|
376
|
+
* List of response types the client supports
|
|
377
|
+
*/
|
|
378
|
+
responseTypes?: string[];
|
|
379
|
+
/**
|
|
380
|
+
* Unix timestamp when the client was registered
|
|
381
|
+
*/
|
|
382
|
+
registrationDate?: number;
|
|
383
|
+
/**
|
|
384
|
+
* The authentication method used by the client at the token endpoint.
|
|
385
|
+
* Values include:
|
|
386
|
+
* - 'client_secret_basic': Uses HTTP Basic Auth with client ID and secret (default for confidential clients)
|
|
387
|
+
* - 'client_secret_post': Uses POST parameters for client authentication
|
|
388
|
+
* - 'none': Used for public clients that can't securely store secrets (SPAs, mobile apps, etc.)
|
|
389
|
+
*
|
|
390
|
+
* Public clients use 'none', while confidential clients use either 'client_secret_basic' or 'client_secret_post'.
|
|
391
|
+
*/
|
|
392
|
+
tokenEndpointAuthMethod: string;
|
|
375
393
|
}
|
|
376
394
|
/**
|
|
377
395
|
* Options for completing an authorization request
|
|
378
396
|
*/
|
|
379
397
|
interface CompleteAuthorizationOptions {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
398
|
+
/**
|
|
399
|
+
* The original parsed authorization request
|
|
400
|
+
*/
|
|
401
|
+
request: AuthRequest;
|
|
402
|
+
/**
|
|
403
|
+
* Identifier for the user granting the authorization
|
|
404
|
+
*/
|
|
405
|
+
userId: string;
|
|
406
|
+
/**
|
|
407
|
+
* Application-specific metadata to associate with this grant
|
|
408
|
+
*/
|
|
409
|
+
metadata: any;
|
|
410
|
+
/**
|
|
411
|
+
* List of scopes that were actually granted (may differ from requested scopes)
|
|
412
|
+
*/
|
|
413
|
+
scope: string[];
|
|
414
|
+
/**
|
|
415
|
+
* Application-specific properties to include with API requests
|
|
416
|
+
* authorized by this grant
|
|
417
|
+
*/
|
|
418
|
+
props: any;
|
|
401
419
|
}
|
|
402
420
|
/**
|
|
403
421
|
* Authorization grant record
|
|
404
422
|
*/
|
|
405
423
|
interface Grant {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Unique identifier for the grant
|
|
426
|
+
*/
|
|
427
|
+
id: string;
|
|
428
|
+
/**
|
|
429
|
+
* Client that received this grant
|
|
430
|
+
*/
|
|
431
|
+
clientId: string;
|
|
432
|
+
/**
|
|
433
|
+
* User who authorized this grant
|
|
434
|
+
*/
|
|
435
|
+
userId: string;
|
|
436
|
+
/**
|
|
437
|
+
* List of scopes that were granted
|
|
438
|
+
*/
|
|
439
|
+
scope: string[];
|
|
440
|
+
/**
|
|
441
|
+
* Application-specific metadata associated with this grant
|
|
442
|
+
*/
|
|
443
|
+
metadata: any;
|
|
444
|
+
/**
|
|
445
|
+
* Encrypted application-specific properties
|
|
446
|
+
*/
|
|
447
|
+
encryptedProps: string;
|
|
448
|
+
/**
|
|
449
|
+
* Unix timestamp when the grant was created
|
|
450
|
+
*/
|
|
451
|
+
createdAt: number;
|
|
452
|
+
/**
|
|
453
|
+
* Unix timestamp when the grant expires (if TTL is configured)
|
|
454
|
+
*/
|
|
455
|
+
expiresAt?: number;
|
|
456
|
+
/**
|
|
457
|
+
* The hash of the current refresh token associated with this grant
|
|
458
|
+
*/
|
|
459
|
+
refreshTokenId?: string;
|
|
460
|
+
/**
|
|
461
|
+
* Wrapped encryption key for the current refresh token
|
|
462
|
+
*/
|
|
463
|
+
refreshTokenWrappedKey?: string;
|
|
464
|
+
/**
|
|
465
|
+
* The hash of the previous refresh token associated with this grant
|
|
466
|
+
* This token is still valid until the new token is first used
|
|
467
|
+
*/
|
|
468
|
+
previousRefreshTokenId?: string;
|
|
469
|
+
/**
|
|
470
|
+
* Wrapped encryption key for the previous refresh token
|
|
471
|
+
*/
|
|
472
|
+
previousRefreshTokenWrappedKey?: string;
|
|
473
|
+
/**
|
|
474
|
+
* The hash of the authorization code associated with this grant
|
|
475
|
+
* Only present during the authorization code exchange process
|
|
476
|
+
*/
|
|
477
|
+
authCodeId?: string;
|
|
478
|
+
/**
|
|
479
|
+
* Wrapped encryption key for the authorization code
|
|
480
|
+
* Only present during the authorization code exchange process
|
|
481
|
+
*/
|
|
482
|
+
authCodeWrappedKey?: string;
|
|
483
|
+
/**
|
|
484
|
+
* PKCE code challenge for this authorization
|
|
485
|
+
* Only present during the authorization code exchange process
|
|
486
|
+
*/
|
|
487
|
+
codeChallenge?: string;
|
|
488
|
+
/**
|
|
489
|
+
* PKCE code challenge method (plain or S256)
|
|
490
|
+
* Only present during the authorization code exchange process
|
|
491
|
+
*/
|
|
492
|
+
codeChallengeMethod?: string;
|
|
493
|
+
/**
|
|
494
|
+
* Resource parameter from authorization request (RFC 8707 Section 2.1)
|
|
495
|
+
* Indicates the protected resource(s) for which access is requested
|
|
496
|
+
*/
|
|
497
|
+
resource?: string | string[];
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Shared fields for Token and TokenSummary
|
|
501
|
+
*/
|
|
502
|
+
interface TokenBase {
|
|
503
|
+
/**
|
|
504
|
+
* Unique identifier for the token (hash of the actual token)
|
|
505
|
+
*/
|
|
506
|
+
id: string;
|
|
507
|
+
/**
|
|
508
|
+
* Identifier of the grant this token is associated with
|
|
509
|
+
*/
|
|
510
|
+
grantId: string;
|
|
511
|
+
/**
|
|
512
|
+
* User ID associated with this token
|
|
513
|
+
*/
|
|
514
|
+
userId: string;
|
|
515
|
+
/**
|
|
516
|
+
* Unix timestamp when the token was created
|
|
517
|
+
*/
|
|
518
|
+
createdAt: number;
|
|
519
|
+
/**
|
|
520
|
+
* Unix timestamp when the token expires
|
|
521
|
+
*/
|
|
522
|
+
expiresAt: number;
|
|
523
|
+
/**
|
|
524
|
+
* Intended audience for this token (RFC 7519 Section 4.1.3)
|
|
525
|
+
* Can be a single string or array of strings
|
|
526
|
+
*/
|
|
527
|
+
audience?: string | string[];
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Token record stored in KV
|
|
531
|
+
* Note: The actual token format is "{userId}:{grantId}:{random-secret}"
|
|
532
|
+
* but we still only store the hash of the full token string.
|
|
533
|
+
* This contains only access tokens; refresh tokens are stored within the grant records.
|
|
534
|
+
*/
|
|
535
|
+
interface Token extends TokenBase {
|
|
536
|
+
/**
|
|
537
|
+
* The encryption key for props, wrapped with this token
|
|
538
|
+
*/
|
|
539
|
+
wrappedEncryptionKey: string;
|
|
540
|
+
/**
|
|
541
|
+
* Denormalized grant information for faster access
|
|
542
|
+
*/
|
|
543
|
+
grant: {
|
|
410
544
|
/**
|
|
411
545
|
* Client that received this grant
|
|
412
546
|
*/
|
|
413
547
|
clientId: string;
|
|
414
|
-
/**
|
|
415
|
-
* User who authorized this grant
|
|
416
|
-
*/
|
|
417
|
-
userId: string;
|
|
418
548
|
/**
|
|
419
549
|
* List of scopes that were granted
|
|
420
550
|
*/
|
|
421
551
|
scope: string[];
|
|
422
|
-
/**
|
|
423
|
-
* Application-specific metadata associated with this grant
|
|
424
|
-
*/
|
|
425
|
-
metadata: any;
|
|
426
552
|
/**
|
|
427
553
|
* Encrypted application-specific properties
|
|
428
554
|
*/
|
|
429
555
|
encryptedProps: string;
|
|
430
|
-
|
|
431
|
-
* Unix timestamp when the grant was created
|
|
432
|
-
*/
|
|
433
|
-
createdAt: number;
|
|
434
|
-
/**
|
|
435
|
-
* Unix timestamp when the grant expires (if TTL is configured)
|
|
436
|
-
*/
|
|
437
|
-
expiresAt?: number;
|
|
438
|
-
/**
|
|
439
|
-
* The hash of the current refresh token associated with this grant
|
|
440
|
-
*/
|
|
441
|
-
refreshTokenId?: string;
|
|
442
|
-
/**
|
|
443
|
-
* Wrapped encryption key for the current refresh token
|
|
444
|
-
*/
|
|
445
|
-
refreshTokenWrappedKey?: string;
|
|
446
|
-
/**
|
|
447
|
-
* The hash of the previous refresh token associated with this grant
|
|
448
|
-
* This token is still valid until the new token is first used
|
|
449
|
-
*/
|
|
450
|
-
previousRefreshTokenId?: string;
|
|
451
|
-
/**
|
|
452
|
-
* Wrapped encryption key for the previous refresh token
|
|
453
|
-
*/
|
|
454
|
-
previousRefreshTokenWrappedKey?: string;
|
|
455
|
-
/**
|
|
456
|
-
* The hash of the authorization code associated with this grant
|
|
457
|
-
* Only present during the authorization code exchange process
|
|
458
|
-
*/
|
|
459
|
-
authCodeId?: string;
|
|
460
|
-
/**
|
|
461
|
-
* Wrapped encryption key for the authorization code
|
|
462
|
-
* Only present during the authorization code exchange process
|
|
463
|
-
*/
|
|
464
|
-
authCodeWrappedKey?: string;
|
|
465
|
-
/**
|
|
466
|
-
* PKCE code challenge for this authorization
|
|
467
|
-
* Only present during the authorization code exchange process
|
|
468
|
-
*/
|
|
469
|
-
codeChallenge?: string;
|
|
470
|
-
/**
|
|
471
|
-
* PKCE code challenge method (plain or S256)
|
|
472
|
-
* Only present during the authorization code exchange process
|
|
473
|
-
*/
|
|
474
|
-
codeChallengeMethod?: string;
|
|
556
|
+
};
|
|
475
557
|
}
|
|
476
558
|
/**
|
|
477
|
-
* Token record
|
|
478
|
-
*
|
|
479
|
-
* but we still only store the hash of the full token string.
|
|
480
|
-
* This contains only access tokens; refresh tokens are stored within the grant records.
|
|
559
|
+
* Token record with decrypted properties
|
|
560
|
+
* Derived from Token but with wrappedEncryptionKey removed and encryptedProps replaced with props
|
|
481
561
|
*/
|
|
482
|
-
interface
|
|
562
|
+
interface TokenSummary<T = any> extends TokenBase {
|
|
563
|
+
/**
|
|
564
|
+
* Denormalized grant information for faster access
|
|
565
|
+
*/
|
|
566
|
+
grant: {
|
|
483
567
|
/**
|
|
484
|
-
*
|
|
485
|
-
*/
|
|
486
|
-
id: string;
|
|
487
|
-
/**
|
|
488
|
-
* Identifier of the grant this token is associated with
|
|
489
|
-
*/
|
|
490
|
-
grantId: string;
|
|
491
|
-
/**
|
|
492
|
-
* User ID associated with this token
|
|
493
|
-
*/
|
|
494
|
-
userId: string;
|
|
495
|
-
/**
|
|
496
|
-
* Unix timestamp when the token was created
|
|
497
|
-
*/
|
|
498
|
-
createdAt: number;
|
|
499
|
-
/**
|
|
500
|
-
* Unix timestamp when the token expires
|
|
568
|
+
* Client that received this grant
|
|
501
569
|
*/
|
|
502
|
-
|
|
570
|
+
clientId: string;
|
|
503
571
|
/**
|
|
504
|
-
*
|
|
572
|
+
* List of scopes that were granted
|
|
505
573
|
*/
|
|
506
|
-
|
|
574
|
+
scope: string[];
|
|
507
575
|
/**
|
|
508
|
-
*
|
|
576
|
+
* Decrypted application-specific properties
|
|
509
577
|
*/
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
* Client that received this grant
|
|
513
|
-
*/
|
|
514
|
-
clientId: string;
|
|
515
|
-
/**
|
|
516
|
-
* List of scopes that were granted
|
|
517
|
-
*/
|
|
518
|
-
scope: string[];
|
|
519
|
-
/**
|
|
520
|
-
* Encrypted application-specific properties
|
|
521
|
-
*/
|
|
522
|
-
encryptedProps: string;
|
|
523
|
-
};
|
|
578
|
+
props: T;
|
|
579
|
+
};
|
|
524
580
|
}
|
|
525
581
|
/**
|
|
526
582
|
* Options for listing operations that support pagination
|
|
527
583
|
*/
|
|
528
584
|
interface ListOptions {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
585
|
+
/**
|
|
586
|
+
* Maximum number of items to return (max 1000)
|
|
587
|
+
*/
|
|
588
|
+
limit?: number;
|
|
589
|
+
/**
|
|
590
|
+
* Cursor for pagination (from a previous listing operation)
|
|
591
|
+
*/
|
|
592
|
+
cursor?: string;
|
|
537
593
|
}
|
|
538
594
|
/**
|
|
539
595
|
* Result of a listing operation with pagination support
|
|
540
596
|
*/
|
|
541
597
|
interface ListResult<T> {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
598
|
+
/**
|
|
599
|
+
* The list of items
|
|
600
|
+
*/
|
|
601
|
+
items: T[];
|
|
602
|
+
/**
|
|
603
|
+
* Cursor to get the next page of results, if there are more results
|
|
604
|
+
*/
|
|
605
|
+
cursor?: string;
|
|
550
606
|
}
|
|
551
607
|
/**
|
|
552
608
|
* Public representation of a grant, with sensitive data removed
|
|
553
609
|
* Used for list operations where the complete grant data isn't needed
|
|
554
610
|
*/
|
|
555
611
|
interface GrantSummary {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
612
|
+
/**
|
|
613
|
+
* Unique identifier for the grant
|
|
614
|
+
*/
|
|
615
|
+
id: string;
|
|
616
|
+
/**
|
|
617
|
+
* Client that received this grant
|
|
618
|
+
*/
|
|
619
|
+
clientId: string;
|
|
620
|
+
/**
|
|
621
|
+
* User who authorized this grant
|
|
622
|
+
*/
|
|
623
|
+
userId: string;
|
|
624
|
+
/**
|
|
625
|
+
* List of scopes that were granted
|
|
626
|
+
*/
|
|
627
|
+
scope: string[];
|
|
628
|
+
/**
|
|
629
|
+
* Application-specific metadata associated with this grant
|
|
630
|
+
*/
|
|
631
|
+
metadata: any;
|
|
632
|
+
/**
|
|
633
|
+
* Unix timestamp when the grant was created
|
|
634
|
+
*/
|
|
635
|
+
createdAt: number;
|
|
636
|
+
/**
|
|
637
|
+
* Unix timestamp when the grant expires (if TTL is configured)
|
|
638
|
+
*/
|
|
639
|
+
expiresAt?: number;
|
|
584
640
|
}
|
|
585
641
|
/**
|
|
586
642
|
* OAuth 2.0 Provider implementation for Cloudflare Workers
|
|
@@ -588,21 +644,21 @@ interface GrantSummary {
|
|
|
588
644
|
* and dynamic client registration.
|
|
589
645
|
*/
|
|
590
646
|
declare class OAuthProvider {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
647
|
+
#private;
|
|
648
|
+
/**
|
|
649
|
+
* Creates a new OAuth provider instance
|
|
650
|
+
* @param options - Configuration options for the provider
|
|
651
|
+
*/
|
|
652
|
+
constructor(options: OAuthProviderOptions);
|
|
653
|
+
/**
|
|
654
|
+
* Main fetch handler for the Worker
|
|
655
|
+
* Routes requests to the appropriate handler based on the URL
|
|
656
|
+
* @param request - The HTTP request
|
|
657
|
+
* @param env - Cloudflare Worker environment variables
|
|
658
|
+
* @param ctx - Cloudflare Worker execution context
|
|
659
|
+
* @returns A Promise resolving to an HTTP Response
|
|
660
|
+
*/
|
|
661
|
+
fetch(request: Request, env: any, ctx: ExecutionContext): Promise<Response>;
|
|
606
662
|
}
|
|
607
|
-
|
|
608
|
-
export {
|
|
663
|
+
//#endregion
|
|
664
|
+
export { AuthRequest, ClientInfo, CompleteAuthorizationOptions, Grant, GrantSummary, ListOptions, ListResult, OAuthHelpers, OAuthProvider, OAuthProvider as default, OAuthProviderOptions, ResolveExternalTokenInput, ResolveExternalTokenResult, Token, TokenBase, TokenExchangeCallbackOptions, TokenExchangeCallbackResult, TokenSummary };
|