@openid4vc/oauth2 0.2.0-alpha-20250109205223

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.
@@ -0,0 +1,2276 @@
1
+ import * as v from 'valibot';
2
+ import { HttpMethod, FetchHeaders, ContentType, OrPromise, Fetch, BaseSchema, FetchResponse, FetchRequestInit, StringWithAutoCompletion } from '@openid4vc/utils';
3
+ export { HttpMethod, InvalidFetchResponseError, Oid4vcTsConfig, getGlobalConfig, setGlobalConfig } from '@openid4vc/utils';
4
+
5
+ declare enum Oauth2ErrorCodes {
6
+ ServerError = "server_error",
7
+ InvalidTarget = "invalid_target",
8
+ InvalidRequest = "invalid_request",
9
+ InvalidToken = "invalid_token",
10
+ InsufficientScope = "insufficient_scope",
11
+ InvalidGrant = "invalid_grant",
12
+ InvalidClient = "invalid_client",
13
+ UnauthorizedClient = "unauthorized_client",
14
+ UnsupportedGrantType = "unsupported_grant_type",
15
+ InvalidScope = "invalid_scope",
16
+ InvalidDpopProof = "invalid_dpop_proof",
17
+ UseDpopNonce = "use_dpop_nonce",
18
+ RedirectToWeb = "redirect_to_web",
19
+ InvalidSession = "invalid_session",
20
+ InsufficientAuthorization = "insufficient_authorization",
21
+ InvalidCredentialRequest = "invalid_credential_request",
22
+ CredentialRequestDenied = "credential_request_denied",
23
+ UnsupportedCredentialType = "unsupported_credential_type",
24
+ UnsupportedCredentialFormat = "unsupported_credential_format",
25
+ InvalidProof = "invalid_proof",
26
+ InvalidNonce = "invalid_nonce",
27
+ InvalidEncryptionParameters = "invalid_encryption_parameters"
28
+ }
29
+ declare const vOauth2ErrorResponse: v.LooseObjectSchema<{
30
+ readonly error: v.UnionSchema<[v.EnumSchema<typeof Oauth2ErrorCodes, undefined>, v.StringSchema<undefined>], undefined>;
31
+ readonly error_description: v.OptionalSchema<v.StringSchema<undefined>, never>;
32
+ readonly error_uri: v.OptionalSchema<v.StringSchema<undefined>, never>;
33
+ }, undefined>;
34
+ type Oauth2ErrorResponse = v.InferOutput<typeof vOauth2ErrorResponse>;
35
+
36
+ declare const vAccessTokenRequest: v.IntersectSchema<[v.LooseObjectSchema<{
37
+ readonly 'pre-authorized_code': v.OptionalSchema<v.StringSchema<undefined>, never>;
38
+ readonly code: v.OptionalSchema<v.StringSchema<undefined>, never>;
39
+ readonly redirect_uri: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>]>, never>;
40
+ readonly refresh_token: v.OptionalSchema<v.StringSchema<undefined>, never>;
41
+ readonly resource: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
42
+ readonly code_verifier: v.OptionalSchema<v.StringSchema<undefined>, never>;
43
+ readonly grant_type: v.UnionSchema<[v.LiteralSchema<"urn:ietf:params:oauth:grant-type:pre-authorized_code", undefined>, v.LiteralSchema<"authorization_code", undefined>, v.LiteralSchema<"refresh_token", undefined>, v.StringSchema<undefined>], undefined>;
44
+ }, undefined>, v.SchemaWithPipe<[v.LooseObjectSchema<{
45
+ readonly tx_code: v.OptionalSchema<v.StringSchema<undefined>, never>;
46
+ readonly user_pin: v.OptionalSchema<v.StringSchema<undefined>, never>;
47
+ }, undefined>, v.CheckAction<{
48
+ tx_code?: string | undefined;
49
+ user_pin?: string | undefined;
50
+ } & {
51
+ [key: string]: unknown;
52
+ }, "If both 'tx_code' and 'user_pin' are present they must match">, v.TransformAction<{
53
+ tx_code?: string | undefined;
54
+ user_pin?: string | undefined;
55
+ } & {
56
+ [key: string]: unknown;
57
+ }, {
58
+ tx_code?: string | undefined;
59
+ }>]>], undefined>;
60
+ type AccessTokenRequest = v.InferOutput<typeof vAccessTokenRequest>;
61
+ declare const vAccessTokenResponse: v.LooseObjectSchema<{
62
+ readonly access_token: v.StringSchema<undefined>;
63
+ readonly token_type: v.StringSchema<undefined>;
64
+ readonly expires_in: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
65
+ readonly scope: v.OptionalSchema<v.StringSchema<undefined>, never>;
66
+ readonly state: v.OptionalSchema<v.StringSchema<undefined>, never>;
67
+ readonly refresh_token: v.OptionalSchema<v.StringSchema<undefined>, never>;
68
+ readonly c_nonce: v.OptionalSchema<v.StringSchema<undefined>, never>;
69
+ readonly c_nonce_expires_in: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
70
+ readonly authorization_details: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{}, undefined>, undefined>, never>;
71
+ }, undefined>;
72
+ type AccessTokenResponse = v.InferOutput<typeof vAccessTokenResponse>;
73
+ declare const vAccessTokenErrorResponse: v.LooseObjectSchema<{
74
+ readonly error: v.UnionSchema<[v.EnumSchema<typeof Oauth2ErrorCodes, undefined>, v.StringSchema<undefined>], undefined>;
75
+ readonly error_description: v.OptionalSchema<v.StringSchema<undefined>, never>;
76
+ readonly error_uri: v.OptionalSchema<v.StringSchema<undefined>, never>;
77
+ }, undefined>;
78
+ type AccessTokenErrorResponse = v.InferOutput<typeof vAccessTokenErrorResponse>;
79
+
80
+ declare const vAuthorizationServerMetadata: v.SchemaWithPipe<[v.LooseObjectSchema<{
81
+ readonly issuer: v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>;
82
+ readonly token_endpoint: v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>;
83
+ readonly token_endpoint_auth_methods_supported: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
84
+ readonly authorization_endpoint: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
85
+ readonly jwks_uri: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
86
+ readonly code_challenge_methods_supported: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
87
+ readonly dpop_signing_alg_values_supported: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
88
+ readonly require_pushed_authorization_requests: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
89
+ readonly pushed_authorization_request_endpoint: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
90
+ readonly introspection_endpoint: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
91
+ readonly introspection_endpoint_auth_methods_supported: v.OptionalSchema<v.ArraySchema<v.UnionSchema<[v.LiteralSchema<"client_secret_jwt", undefined>, v.LiteralSchema<"private_key_jwt", undefined>, v.StringSchema<undefined>], undefined>, undefined>, never>;
92
+ readonly introspection_endpoint_auth_signing_alg_values_supported: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.CheckAction<string, "alg value may not be 'none'">]>, undefined>, never>;
93
+ readonly authorization_challenge_endpoint: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
94
+ readonly 'pre-authorized_grant_anonymous_access_supported': v.OptionalSchema<v.BooleanSchema<undefined>, never>;
95
+ }, undefined>, v.CheckAction<{
96
+ issuer: string;
97
+ token_endpoint: string;
98
+ token_endpoint_auth_methods_supported?: string[] | undefined;
99
+ authorization_endpoint?: string | undefined;
100
+ jwks_uri?: string | undefined;
101
+ code_challenge_methods_supported?: string[] | undefined;
102
+ dpop_signing_alg_values_supported?: string[] | undefined;
103
+ require_pushed_authorization_requests?: boolean | undefined;
104
+ pushed_authorization_request_endpoint?: string | undefined;
105
+ introspection_endpoint?: string | undefined;
106
+ introspection_endpoint_auth_methods_supported?: string[] | undefined;
107
+ introspection_endpoint_auth_signing_alg_values_supported?: string[] | undefined;
108
+ authorization_challenge_endpoint?: string | undefined;
109
+ 'pre-authorized_grant_anonymous_access_supported'?: boolean | undefined;
110
+ } & {
111
+ [key: string]: unknown;
112
+ }, "Metadata value 'introspection_endpoint_auth_signing_alg_values_supported' must be defined if metadata 'introspection_endpoint_auth_methods_supported' value contains values 'private_key_jwt' or 'client_secret_jwt'">]>;
113
+ type AuthorizationServerMetadata = v.InferOutput<typeof vAuthorizationServerMetadata>;
114
+
115
+ interface ClientAuthenticationDynamicOptions {
116
+ clientId: string;
117
+ clientSecret: string;
118
+ }
119
+ /**
120
+ * Dynamicaly get the client authentication method based on endpoint type and authorization server.
121
+ * Only `client_secret_post` and `client_secret_basic` supported.
122
+ */
123
+ declare function clientAuthenticationDynamic(options: ClientAuthenticationDynamicOptions): ClientAuthenticationCallback;
124
+ /**
125
+ * Options for client authentication
126
+ */
127
+ interface ClientAuthenticationCallbackOptions {
128
+ /**
129
+ * Metadata of the authorization server
130
+ */
131
+ authorizationServerMetata: AuthorizationServerMetadata;
132
+ /**
133
+ * URL to which the request will be made
134
+ */
135
+ url: string;
136
+ /**
137
+ * http method that will be used
138
+ */
139
+ method: HttpMethod;
140
+ /**
141
+ * Headers for the request. You can modify this object
142
+ */
143
+ headers: FetchHeaders;
144
+ contentType: ContentType;
145
+ /**
146
+ * The body as a JSON object. If content type `x-www-form-urlencoded`
147
+ * is used, it will be encoded after this call.
148
+ *
149
+ * You can modify this object
150
+ */
151
+ body: Record<string, unknown>;
152
+ }
153
+ /**
154
+ * Callback method to determine the client authentication for a request.
155
+ */
156
+ type ClientAuthenticationCallback = (options: ClientAuthenticationCallbackOptions) => Promise<void> | void;
157
+ interface ClientAuthenticationClientSecretPostOptions {
158
+ clientId: string;
159
+ clientSecret: string;
160
+ }
161
+ /**
162
+ * Client authentication using `client_secret_post` option
163
+ */
164
+ declare function clientAuthenticationClientSecretPost(options: ClientAuthenticationClientSecretPostOptions): ClientAuthenticationCallback;
165
+ interface ClientAuthenticationClientSecretBasicOptions {
166
+ clientId: string;
167
+ clientSecret: string;
168
+ }
169
+ /**
170
+ * Client authentication using `client_secret_basic` option
171
+ */
172
+ declare function clientAuthenticationClientSecretBasic(options: ClientAuthenticationClientSecretBasicOptions): ClientAuthenticationCallback;
173
+ /**
174
+ * No client authentication
175
+ */
176
+ declare function clientAuthenticationNone(): () => void;
177
+
178
+ declare const vJwk: v.LooseObjectSchema<{
179
+ readonly kty: v.StringSchema<undefined>;
180
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
181
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
182
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
183
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
184
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
185
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
186
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
187
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
188
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
189
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
190
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
191
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
192
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
193
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
194
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
195
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
196
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
197
+ }, undefined>, undefined>, never>;
198
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
199
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
200
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
201
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
202
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
203
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
204
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
205
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
206
+ }, undefined>;
207
+ type Jwk = v.InferOutput<typeof vJwk>;
208
+ declare const vJwkSet: v.LooseObjectSchema<{
209
+ readonly keys: v.ArraySchema<v.LooseObjectSchema<{
210
+ readonly kty: v.StringSchema<undefined>;
211
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
212
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
213
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
214
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
215
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
216
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
217
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
218
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
219
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
220
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
221
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
222
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
223
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
224
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
225
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
226
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
227
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
228
+ }, undefined>, undefined>, never>;
229
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
230
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
231
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
232
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
233
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
234
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
235
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
236
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
237
+ }, undefined>, undefined>;
238
+ }, undefined>;
239
+ type JwkSet = v.InferOutput<typeof vJwkSet>;
240
+
241
+ type JwtSignerDid = {
242
+ method: 'did';
243
+ didUrl: string;
244
+ alg: string;
245
+ };
246
+ type JwtSignerJwk = {
247
+ method: 'jwk';
248
+ publicJwk: Jwk;
249
+ alg: string;
250
+ };
251
+ type JwtSignerX5c = {
252
+ method: 'x5c';
253
+ x5c: string[];
254
+ alg: string;
255
+ };
256
+ type JwtSignerTrustChain = {
257
+ method: 'trustChain';
258
+ trustChain: string[];
259
+ alg: string;
260
+ kid: string;
261
+ };
262
+ type JwtSignerCustom = {
263
+ method: 'custom';
264
+ alg: string;
265
+ };
266
+ type JwtSigner = JwtSignerDid | JwtSignerJwk | JwtSignerX5c | JwtSignerTrustChain | JwtSignerCustom;
267
+ type JwtSignerWithJwk = JwtSigner & {
268
+ publicJwk: Jwk;
269
+ };
270
+ declare const vCompactJwt: v.SchemaWithPipe<[v.StringSchema<undefined>, v.RegexAction<string, "Not a valid compact jwt">]>;
271
+ declare const vJwtPayload: v.LooseObjectSchema<{
272
+ readonly iss: v.OptionalSchema<v.StringSchema<undefined>, never>;
273
+ readonly aud: v.OptionalSchema<v.StringSchema<undefined>, never>;
274
+ readonly iat: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
275
+ readonly exp: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
276
+ readonly nbf: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
277
+ readonly nonce: v.OptionalSchema<v.StringSchema<undefined>, never>;
278
+ readonly jti: v.OptionalSchema<v.StringSchema<undefined>, never>;
279
+ readonly cnf: v.OptionalSchema<v.LooseObjectSchema<{
280
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
281
+ readonly kty: v.StringSchema<undefined>;
282
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
283
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
284
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
285
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
286
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
287
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
288
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
289
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
290
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
291
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
292
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
293
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
294
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
295
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
296
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
297
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
298
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
299
+ }, undefined>, undefined>, never>;
300
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
301
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
302
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
303
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
304
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
305
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
306
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
307
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
308
+ }, undefined>, never>;
309
+ readonly jkt: v.OptionalSchema<v.StringSchema<undefined>, never>;
310
+ }, undefined>, never>;
311
+ readonly status: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, never>;
312
+ }, undefined>;
313
+ type JwtPayload = v.InferOutput<typeof vJwtPayload>;
314
+ declare const vJwtHeader: v.LooseObjectSchema<{
315
+ readonly alg: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CheckAction<string, "alg value may not be 'none'">]>;
316
+ readonly typ: v.OptionalSchema<v.StringSchema<undefined>, never>;
317
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
318
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
319
+ readonly kty: v.StringSchema<undefined>;
320
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
321
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
322
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
323
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
324
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
325
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
326
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
327
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
328
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
329
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
330
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
331
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
332
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
333
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
334
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
335
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
336
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
337
+ }, undefined>, undefined>, never>;
338
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
339
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
340
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
341
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
342
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
343
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
344
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
345
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
346
+ }, undefined>, never>;
347
+ readonly x5c: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
348
+ readonly trust_chain: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
349
+ }, undefined>;
350
+ type JwtHeader = v.InferOutput<typeof vJwtHeader>;
351
+
352
+ /**
353
+ * Supported hashing algorithms
354
+ */
355
+ declare enum HashAlgorithm {
356
+ Sha256 = "SHA-256"
357
+ }
358
+ /**
359
+ * Callback used for operations that require hashing
360
+ */
361
+ type HashCallback = (data: Uint8Array, alg: HashAlgorithm) => OrPromise<Uint8Array>;
362
+ type GenerateRandomCallback = (byteLength: number) => OrPromise<Uint8Array>;
363
+ type SignJwtCallback = (jwtSigner: JwtSigner, jwt: {
364
+ header: JwtHeader;
365
+ payload: JwtPayload;
366
+ }) => OrPromise<{
367
+ jwt: string;
368
+ signerJwk: Jwk;
369
+ }>;
370
+ type VerifyJwtCallback = (jwtSigner: JwtSigner, jwt: {
371
+ header: JwtHeader;
372
+ payload: JwtPayload;
373
+ compact: string;
374
+ }) => OrPromise<{
375
+ verified: true;
376
+ signerJwk: Jwk;
377
+ } | {
378
+ verified: false;
379
+ signerJwk?: Jwk;
380
+ }>;
381
+ /**
382
+ * Callback context provides the callbacks that are required for the oid4vc library
383
+ */
384
+ interface CallbackContext {
385
+ /**
386
+ * Custom fetch implementation to use
387
+ */
388
+ fetch?: Fetch;
389
+ /**
390
+ * Hash callback used for e.g. dpop and pkce
391
+ */
392
+ hash: HashCallback;
393
+ /**
394
+ * Sign jwt callback for signing of Json Web Tokens
395
+ */
396
+ signJwt: SignJwtCallback;
397
+ /**
398
+ * Verify jwt callback for verification of Json Web Tokens
399
+ */
400
+ verifyJwt: VerifyJwtCallback;
401
+ /**
402
+ * Generate random callback to generate random bytes. Used for
403
+ * e.g. the 'jti' value in a dpop jwt, and 'code_verifier' in pkce.
404
+ */
405
+ generateRandom: GenerateRandomCallback;
406
+ /**
407
+ * Extend a request to the authorization server with client authentication
408
+ * parameters. If you're not using client authentication, you can set this
409
+ * to `clientAuthenticationNone()`
410
+ *
411
+ * There are three default client authentication methods provided:
412
+ * - `clientAuthenticationClientSecretPost`
413
+ * - `clientAuthenticationClientSecretBasic`
414
+ * - `clientAuthenticationNone`
415
+ *
416
+ * A custom implementation can be made for other methods, or allowing complex
417
+ * scenarios where multiple authorization servers are supported.
418
+ */
419
+ clientAuthentication: ClientAuthenticationCallback;
420
+ }
421
+
422
+ interface CalculateJwkThumbprintOptions {
423
+ /**
424
+ * The jwk to calcualte the thumbprint for.
425
+ */
426
+ jwk: Jwk;
427
+ /**
428
+ * The hashing algorithm to use for calculating the thumbprint
429
+ */
430
+ hashAlgorithm: HashAlgorithm;
431
+ /**
432
+ * The hash callback to calculate the digest
433
+ */
434
+ hashCallback: HashCallback;
435
+ }
436
+ declare function calculateJwkThumbprint(options: CalculateJwkThumbprintOptions): Promise<string>;
437
+
438
+ declare function isJwkInSet({ jwk, jwks, callbacks, }: {
439
+ jwk: Jwk;
440
+ jwks: Jwk[];
441
+ callbacks: Pick<CallbackContext, 'hash'>;
442
+ }): Promise<boolean>;
443
+
444
+ declare const vAccessTokenProfileJwtPayload: v.LooseObjectSchema<{
445
+ readonly iss: v.StringSchema<undefined>;
446
+ readonly exp: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
447
+ readonly iat: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
448
+ readonly aud: v.StringSchema<undefined>;
449
+ readonly sub: v.StringSchema<undefined>;
450
+ readonly client_id: v.OptionalSchema<v.StringSchema<undefined>, never>;
451
+ readonly jti: v.StringSchema<undefined>;
452
+ readonly scope: v.OptionalSchema<v.StringSchema<undefined>, never>;
453
+ readonly nbf: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
454
+ readonly nonce: v.OptionalSchema<v.StringSchema<undefined>, never>;
455
+ readonly cnf: v.OptionalSchema<v.LooseObjectSchema<{
456
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
457
+ readonly kty: v.StringSchema<undefined>;
458
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
459
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
460
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
461
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
462
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
463
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
464
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
465
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
466
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
467
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
468
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
469
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
470
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
471
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
472
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
473
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
474
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
475
+ }, undefined>, undefined>, never>;
476
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
477
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
478
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
479
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
480
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
481
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
482
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
483
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
484
+ }, undefined>, never>;
485
+ readonly jkt: v.OptionalSchema<v.StringSchema<undefined>, never>;
486
+ }, undefined>, never>;
487
+ readonly status: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, never>;
488
+ }, undefined>;
489
+ type AccessTokenProfileJwtPayload = v.InferOutput<typeof vAccessTokenProfileJwtPayload>;
490
+
491
+ interface VerifyJwtOptions {
492
+ /**
493
+ * Compact jwt
494
+ */
495
+ compact: string;
496
+ /**
497
+ * Header of the jwt
498
+ */
499
+ header: JwtHeader;
500
+ /**
501
+ * Payload of the jwt.
502
+ */
503
+ payload: JwtPayload;
504
+ /**
505
+ * If not provided current time will be used.
506
+ *
507
+ * @default new Date()
508
+ */
509
+ now?: Date;
510
+ /**
511
+ * Whether to skip time based validation of `nbf` and `exp`.
512
+ * @default false
513
+ */
514
+ skipTimeBasedValidation?: boolean;
515
+ /**
516
+ * Callback to verify jwt signature
517
+ */
518
+ verifyJwtCallback: VerifyJwtCallback;
519
+ /**
520
+ * Signer of the jwt
521
+ */
522
+ signer: JwtSigner;
523
+ /**
524
+ * Custom error message
525
+ */
526
+ errorMessage?: string;
527
+ /**
528
+ * Allowed skew time in seconds for validity of token. Used for `exp` and `nbf`
529
+ * verification.
530
+ *
531
+ * @default 0
532
+ */
533
+ allowedSkewInSeconds?: number;
534
+ /**
535
+ * Expected value for the 'aud' claim
536
+ */
537
+ expectedAudience?: string;
538
+ /**
539
+ * Expected value for the 'iss' claim
540
+ */
541
+ expectedIssuer?: string;
542
+ /**
543
+ * Expected value for the 'nonce' claim
544
+ */
545
+ expectedNonce?: string;
546
+ /**
547
+ * Expected value for the 'sub' claim
548
+ */
549
+ expectedSubject?: string;
550
+ }
551
+ interface VerifyJwtReturn {
552
+ signer: JwtSignerWithJwk;
553
+ }
554
+ declare function verifyJwt(options: VerifyJwtOptions): Promise<VerifyJwtReturn>;
555
+
556
+ interface DecodeJwtOptions<HeaderSchema extends BaseSchema | undefined, PayloadSchema extends BaseSchema | undefined> {
557
+ /**
558
+ * The comapct encoded jwt
559
+ */
560
+ jwt: string;
561
+ /**
562
+ * Schema to use for validating the header. If not provided the
563
+ * default `vJwtHeader` schema will be used
564
+ */
565
+ headerSchema?: HeaderSchema;
566
+ /**
567
+ * Schema to use for validating the payload. If not provided the
568
+ * default `vJwtPayload` schema will be used
569
+ */
570
+ payloadSchema?: PayloadSchema;
571
+ }
572
+ type DecodeJwtResult<HeaderSchema extends BaseSchema | undefined = undefined, PayloadSchema extends BaseSchema | undefined = undefined> = {
573
+ header: InferSchemaOutput<HeaderSchema, typeof vJwtHeader>;
574
+ payload: InferSchemaOutput<PayloadSchema, typeof vJwtPayload>;
575
+ signature: string;
576
+ };
577
+ declare function decodeJwt<HeaderSchema extends BaseSchema | undefined = undefined, PayloadSchema extends BaseSchema | undefined = undefined>(options: DecodeJwtOptions<HeaderSchema, PayloadSchema>): DecodeJwtResult<HeaderSchema, PayloadSchema>;
578
+ declare function jwtHeaderFromJwtSigner(signer: JwtSigner): {
579
+ readonly alg: string;
580
+ readonly kid: string;
581
+ readonly trust_chain?: undefined;
582
+ readonly jwk?: undefined;
583
+ readonly x5c?: undefined;
584
+ } | {
585
+ readonly alg: string;
586
+ readonly kid: string;
587
+ readonly trust_chain: string[];
588
+ readonly jwk?: undefined;
589
+ readonly x5c?: undefined;
590
+ } | {
591
+ readonly alg: string;
592
+ readonly jwk: {
593
+ kty: string;
594
+ crv?: string | undefined;
595
+ x?: string | undefined;
596
+ y?: string | undefined;
597
+ e?: string | undefined;
598
+ n?: string | undefined;
599
+ alg?: string | undefined;
600
+ d?: string | undefined;
601
+ dp?: string | undefined;
602
+ dq?: string | undefined;
603
+ ext?: boolean | undefined;
604
+ k?: string | undefined;
605
+ key_ops?: string | undefined;
606
+ kid?: string | undefined;
607
+ oth?: ({
608
+ d?: string | undefined;
609
+ r?: string | undefined;
610
+ t?: string | undefined;
611
+ } & {
612
+ [key: string]: unknown;
613
+ })[] | undefined;
614
+ p?: string | undefined;
615
+ q?: string | undefined;
616
+ qi?: string | undefined;
617
+ use?: string | undefined;
618
+ x5c?: string | undefined;
619
+ x5t?: string | undefined;
620
+ 'x5t#S256'?: string | undefined;
621
+ x5u?: string | undefined;
622
+ } & {
623
+ [key: string]: unknown;
624
+ };
625
+ readonly kid: string | undefined;
626
+ readonly trust_chain?: undefined;
627
+ readonly x5c?: undefined;
628
+ } | {
629
+ readonly alg: string;
630
+ readonly x5c: string[];
631
+ readonly kid?: undefined;
632
+ readonly trust_chain?: undefined;
633
+ readonly jwk?: undefined;
634
+ } | {
635
+ alg: string;
636
+ readonly kid?: undefined;
637
+ readonly trust_chain?: undefined;
638
+ readonly jwk?: undefined;
639
+ readonly x5c?: undefined;
640
+ };
641
+ declare function jwtSignerFromJwt({ header, payload }: Pick<DecodeJwtResult, 'header' | 'payload'>): JwtSigner;
642
+ type IsSchemaProvided<T> = T extends undefined ? false : true;
643
+ type InferSchemaOutput<ProvidedSchema extends BaseSchema | undefined, DefaultSchema extends BaseSchema> = IsSchemaProvided<ProvidedSchema> extends true ? ProvidedSchema extends BaseSchema ? v.InferOutput<ProvidedSchema> : never : v.InferOutput<DefaultSchema>;
644
+
645
+ interface RequestLike {
646
+ headers: FetchHeaders;
647
+ method: HttpMethod;
648
+ url: string;
649
+ }
650
+
651
+ interface RequestDpopOptions {
652
+ /**
653
+ * Dpop nonce to use for constructing the dpop jwt
654
+ */
655
+ nonce?: string;
656
+ /**
657
+ * The signer of the dpop jwt
658
+ */
659
+ signer: JwtSignerJwk;
660
+ }
661
+
662
+ declare const vClientAttestationJwtPayload: v.LooseObjectSchema<{
663
+ readonly iss: v.StringSchema<undefined>;
664
+ readonly sub: v.StringSchema<undefined>;
665
+ readonly exp: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
666
+ readonly cnf: v.LooseObjectSchema<{
667
+ readonly jwk: v.LooseObjectSchema<{
668
+ readonly kty: v.StringSchema<undefined>;
669
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
670
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
671
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
672
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
673
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
674
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
675
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
676
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
677
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
678
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
679
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
680
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
681
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
682
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
683
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
684
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
685
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
686
+ }, undefined>, undefined>, never>;
687
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
688
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
689
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
690
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
691
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
692
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
693
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
694
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
695
+ }, undefined>;
696
+ readonly key_type: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["software", "hardware", "tee", "secure_enclave", "strong_box", "secure_element", "hsm"], undefined>, v.StringSchema<undefined>], undefined>, never>;
697
+ readonly user_authentication: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["system_biometry", "system_pin", "internal_biometry", "internal_pin", "secure_element_pin"], undefined>, v.StringSchema<undefined>], undefined>, never>;
698
+ }, undefined>;
699
+ readonly aal: v.OptionalSchema<v.StringSchema<undefined>, never>;
700
+ readonly aud: v.OptionalSchema<v.StringSchema<undefined>, never>;
701
+ readonly iat: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
702
+ readonly nbf: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
703
+ readonly nonce: v.OptionalSchema<v.StringSchema<undefined>, never>;
704
+ readonly jti: v.OptionalSchema<v.StringSchema<undefined>, never>;
705
+ readonly status: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, never>;
706
+ }, undefined>;
707
+ type ClientAttestationJwtPayload = v.InferOutput<typeof vClientAttestationJwtPayload>;
708
+ declare const vClientAttestationJwtHeader: v.LooseObjectSchema<{
709
+ readonly typ: v.LiteralSchema<"oauth-client-attestation+jwt", undefined>;
710
+ readonly alg: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CheckAction<string, "alg value may not be 'none'">]>;
711
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
712
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
713
+ readonly kty: v.StringSchema<undefined>;
714
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
715
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
716
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
717
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
718
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
719
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
720
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
721
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
722
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
723
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
724
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
725
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
726
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
727
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
728
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
729
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
730
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
731
+ }, undefined>, undefined>, never>;
732
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
733
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
734
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
735
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
736
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
737
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
738
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
739
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
740
+ }, undefined>, never>;
741
+ readonly x5c: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
742
+ readonly trust_chain: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
743
+ }, undefined>;
744
+ type ClientAttestationJwtHeader = v.InferOutput<typeof vClientAttestationJwtHeader>;
745
+ declare const vClientAttestationPopJwtPayload: v.LooseObjectSchema<{
746
+ readonly iss: v.StringSchema<undefined>;
747
+ readonly exp: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
748
+ readonly aud: v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>;
749
+ readonly jti: v.StringSchema<undefined>;
750
+ readonly nonce: v.OptionalSchema<v.StringSchema<undefined>, never>;
751
+ readonly iat: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
752
+ readonly nbf: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
753
+ readonly cnf: v.OptionalSchema<v.LooseObjectSchema<{
754
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
755
+ readonly kty: v.StringSchema<undefined>;
756
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
757
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
758
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
759
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
760
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
761
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
762
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
763
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
764
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
765
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
766
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
767
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
768
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
769
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
770
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
771
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
772
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
773
+ }, undefined>, undefined>, never>;
774
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
775
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
776
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
777
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
778
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
779
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
780
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
781
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
782
+ }, undefined>, never>;
783
+ readonly jkt: v.OptionalSchema<v.StringSchema<undefined>, never>;
784
+ }, undefined>, never>;
785
+ readonly status: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, never>;
786
+ }, undefined>;
787
+ type ClientAttestationPopJwtPayload = v.InferOutput<typeof vClientAttestationPopJwtPayload>;
788
+ declare const vClientAttestationPopJwtHeader: v.LooseObjectSchema<{
789
+ readonly typ: v.LiteralSchema<"oauth-client-attestation-pop+jwt", undefined>;
790
+ readonly alg: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CheckAction<string, "alg value may not be 'none'">]>;
791
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
792
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
793
+ readonly kty: v.StringSchema<undefined>;
794
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
795
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
796
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
797
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
798
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
799
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
800
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
801
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
802
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
803
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
804
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
805
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
806
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
807
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
808
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
809
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
810
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
811
+ }, undefined>, undefined>, never>;
812
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
813
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
814
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
815
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
816
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
817
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
818
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
819
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
820
+ }, undefined>, never>;
821
+ readonly x5c: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
822
+ readonly trust_chain: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
823
+ }, undefined>;
824
+ type ClientAttestationPopJwtHeader = v.InferOutput<typeof vClientAttestationPopJwtHeader>;
825
+
826
+ interface RequestClientAttestationOptions {
827
+ /**
828
+ * Dpop nonce to use for constructing the client attestation pop jwt
829
+ */
830
+ nonce?: string;
831
+ /**
832
+ * Expiration time of the client attestation pop jwt.
833
+ *
834
+ * @default 5 minutes after issuance date
835
+ */
836
+ expiresAt?: Date;
837
+ /**
838
+ * The client attestation jwt to create the pop for.
839
+ */
840
+ jwt: string;
841
+ /**
842
+ * The signer of the client attestation pop jwt
843
+ */
844
+ signer: JwtSignerJwk;
845
+ /**
846
+ * Whether to include the legacy draft 2 `client_assertion` and `client_assertion_type` properties
847
+ * IN ADDITION to the new header syntax
848
+ *
849
+ * @default false
850
+ */
851
+ includeLegacyDraft2ClientAssertion?: boolean;
852
+ }
853
+
854
+ interface Oauth2ErrorOptions {
855
+ cause?: unknown;
856
+ }
857
+ declare class Oauth2Error extends Error {
858
+ readonly cause?: unknown;
859
+ constructor(message?: string, options?: Oauth2ErrorOptions);
860
+ }
861
+
862
+ declare class Oauth2JwtVerificationError extends Oauth2Error {
863
+ constructor(message?: string, options?: Oauth2ErrorOptions);
864
+ }
865
+
866
+ declare class Oauth2JwtParseError extends Oauth2Error {
867
+ constructor(message?: string);
868
+ }
869
+
870
+ declare enum SupportedAuthenticationScheme {
871
+ Bearer = "Bearer",
872
+ DPoP = "DPoP"
873
+ }
874
+
875
+ interface WwwAuthenticateHeaderChallenge {
876
+ scheme: SupportedAuthenticationScheme | (string & {});
877
+ /**
878
+ * Space delimited scope value that lists scopes required
879
+ * to access this resource.
880
+ */
881
+ scope?: string;
882
+ /**
883
+ * Error should only be undefined if no access token was provided at all
884
+ */
885
+ error?: Oauth2ErrorCodes | string;
886
+ error_description?: string;
887
+ /**
888
+ * Additional payload items to include in the Www-Authenticate
889
+ * header response.
890
+ */
891
+ additionalPayload?: Record<string, string>;
892
+ }
893
+ declare class Oauth2ResourceUnauthorizedError extends Oauth2Error {
894
+ readonly wwwAuthenticateHeaders: WwwAuthenticateHeaderChallenge[];
895
+ constructor(internalMessage: string | undefined, wwwAuthenticateHeaders: WwwAuthenticateHeaderChallenge | Array<WwwAuthenticateHeaderChallenge>);
896
+ static fromHeaderValue(value: string): Oauth2ResourceUnauthorizedError;
897
+ toHeaderValue(): string;
898
+ }
899
+
900
+ declare class Oauth2ClientErrorResponseError extends Oauth2Error {
901
+ readonly errorResponse: Oauth2ErrorResponse;
902
+ readonly response: FetchResponse;
903
+ constructor(message: string, errorResponse: Oauth2ErrorResponse, response: FetchResponse);
904
+ }
905
+
906
+ declare const vAuthorizationChallengeRequest: v.LooseObjectSchema<{
907
+ readonly client_id: v.OptionalSchema<v.StringSchema<undefined>, never>;
908
+ readonly auth_session: v.OptionalSchema<v.StringSchema<undefined>, never>;
909
+ readonly presentation_during_issuance_session: v.OptionalSchema<v.StringSchema<undefined>, never>;
910
+ readonly redirect_uri: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>]>, never>;
911
+ readonly resource: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CheckAction<string, "url must be an https:// url">]>, never>;
912
+ readonly scope: v.OptionalSchema<v.StringSchema<undefined>, never>;
913
+ readonly issuer_state: v.OptionalSchema<v.StringSchema<undefined>, never>;
914
+ readonly dpop_jkt: v.OptionalSchema<v.StringSchema<undefined>, never>;
915
+ readonly code_challenge: v.OptionalSchema<v.StringSchema<undefined>, never>;
916
+ readonly code_challenge_method: v.OptionalSchema<v.StringSchema<undefined>, never>;
917
+ }, undefined>;
918
+ type AuthorizationChallengeRequest = v.InferOutput<typeof vAuthorizationChallengeRequest>;
919
+ declare const vAuthorizationChallengeResponse: v.LooseObjectSchema<{
920
+ readonly authorization_code: v.StringSchema<undefined>;
921
+ }, undefined>;
922
+ type AuthorizationChallengeResponse = v.InferOutput<typeof vAuthorizationChallengeResponse>;
923
+ declare const vAuthorizationChallengeErrorResponse: v.LooseObjectSchema<{
924
+ readonly auth_session: v.OptionalSchema<v.StringSchema<undefined>, never>;
925
+ readonly request_uri: v.OptionalSchema<v.StringSchema<undefined>, never>;
926
+ readonly expires_in: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
927
+ readonly presentation: v.OptionalSchema<v.StringSchema<undefined>, never>;
928
+ readonly error: v.UnionSchema<[v.EnumSchema<typeof Oauth2ErrorCodes, undefined>, v.StringSchema<undefined>], undefined>;
929
+ readonly error_description: v.OptionalSchema<v.StringSchema<undefined>, never>;
930
+ readonly error_uri: v.OptionalSchema<v.StringSchema<undefined>, never>;
931
+ }, undefined>;
932
+ type AuthorizationChallengeErrorResponse = v.InferOutput<typeof vAuthorizationChallengeErrorResponse>;
933
+
934
+ declare class Oauth2ClientAuthorizationChallengeError extends Oauth2ClientErrorResponseError {
935
+ readonly errorResponse: AuthorizationChallengeErrorResponse;
936
+ constructor(message: string, errorResponse: AuthorizationChallengeErrorResponse, response: FetchResponse);
937
+ }
938
+
939
+ interface Oauth2ServerErrorResponseErrorOptions extends Oauth2ErrorOptions {
940
+ internalMessage?: string;
941
+ /**
942
+ * @default 400
943
+ */
944
+ status?: number;
945
+ }
946
+ declare class Oauth2ServerErrorResponseError extends Oauth2Error {
947
+ readonly errorResponse: Oauth2ErrorResponse;
948
+ readonly status: number;
949
+ constructor(errorResponse: Oauth2ErrorResponse, options?: Oauth2ServerErrorResponseErrorOptions);
950
+ }
951
+
952
+ /**
953
+ * fetch authorization server metadata. It first tries to fetch the openid configuration. If that reutrns
954
+ * a 404, the oauth authorization server metadata will be tries.
955
+ */
956
+ declare function fetchAuthorizationServerMetadata(issuer: string, fetch?: Fetch): Promise<AuthorizationServerMetadata | null>;
957
+ declare function getAuthorizationServerMetadataFromList(authorizationServersMetadata: AuthorizationServerMetadata[], issuer: string): {
958
+ issuer: string;
959
+ token_endpoint: string;
960
+ token_endpoint_auth_methods_supported?: string[] | undefined;
961
+ authorization_endpoint?: string | undefined;
962
+ jwks_uri?: string | undefined;
963
+ code_challenge_methods_supported?: string[] | undefined;
964
+ dpop_signing_alg_values_supported?: string[] | undefined;
965
+ require_pushed_authorization_requests?: boolean | undefined;
966
+ pushed_authorization_request_endpoint?: string | undefined;
967
+ introspection_endpoint?: string | undefined;
968
+ introspection_endpoint_auth_methods_supported?: string[] | undefined;
969
+ introspection_endpoint_auth_signing_alg_values_supported?: string[] | undefined;
970
+ authorization_challenge_endpoint?: string | undefined;
971
+ 'pre-authorized_grant_anonymous_access_supported'?: boolean | undefined;
972
+ } & {
973
+ [key: string]: unknown;
974
+ };
975
+
976
+ /**
977
+ * Fetch JWKs from jwks_uri in authorization server metadata
978
+ *
979
+ * Returns null if 404 is returned
980
+ * Returns validated metadata if successfull response
981
+ * Throws error otherwise
982
+ *
983
+ * @throws {ValidationError} if successfull response but validation of response failed
984
+ * @throws {InvalidFetchResponseError} if unsuccesful response
985
+ * @throws {Oauth2Error} if authorization server does not have a jwks_uri
986
+ */
987
+ declare function fetchJwks(authorizationServer: AuthorizationServerMetadata, fetch?: Fetch): Promise<JwkSet>;
988
+
989
+ /**
990
+ * Fetch well known metadata and validate the response.
991
+ *
992
+ * Returns null if 404 is returned
993
+ * Returns validated metadata if successfull response
994
+ * Throws error otherwise
995
+ *
996
+ * @throws {ValidationError} if successfull response but validation of response failed
997
+ * @throws {InvalidFetchResponseError} if no successfull or 404 response
998
+ * @throws {Error} if parsing json from response fails
999
+ */
1000
+ declare function fetchWellKnownMetadata<Schema extends BaseSchema>(wellKnownMetadataUrl: string, schema: Schema, fetch?: Fetch): Promise<v.InferOutput<Schema> | null>;
1001
+
1002
+ declare const vTokenIntrospectionResponse: v.LooseObjectSchema<{
1003
+ readonly active: v.BooleanSchema<undefined>;
1004
+ readonly scope: v.OptionalSchema<v.StringSchema<undefined>, never>;
1005
+ readonly client_id: v.OptionalSchema<v.StringSchema<undefined>, never>;
1006
+ readonly username: v.OptionalSchema<v.StringSchema<undefined>, never>;
1007
+ readonly token_type: v.OptionalSchema<v.StringSchema<undefined>, never>;
1008
+ readonly exp: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
1009
+ readonly iat: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
1010
+ readonly nbf: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, never>;
1011
+ readonly sub: v.OptionalSchema<v.StringSchema<undefined>, never>;
1012
+ readonly aud: v.OptionalSchema<v.StringSchema<undefined>, never>;
1013
+ readonly iss: v.OptionalSchema<v.StringSchema<undefined>, never>;
1014
+ readonly jti: v.OptionalSchema<v.StringSchema<undefined>, never>;
1015
+ readonly cnf: v.OptionalSchema<v.LooseObjectSchema<{
1016
+ readonly jwk: v.OptionalSchema<v.LooseObjectSchema<{
1017
+ readonly kty: v.StringSchema<undefined>;
1018
+ readonly crv: v.OptionalSchema<v.StringSchema<undefined>, never>;
1019
+ readonly x: v.OptionalSchema<v.StringSchema<undefined>, never>;
1020
+ readonly y: v.OptionalSchema<v.StringSchema<undefined>, never>;
1021
+ readonly e: v.OptionalSchema<v.StringSchema<undefined>, never>;
1022
+ readonly n: v.OptionalSchema<v.StringSchema<undefined>, never>;
1023
+ readonly alg: v.OptionalSchema<v.StringSchema<undefined>, never>;
1024
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
1025
+ readonly dp: v.OptionalSchema<v.StringSchema<undefined>, never>;
1026
+ readonly dq: v.OptionalSchema<v.StringSchema<undefined>, never>;
1027
+ readonly ext: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
1028
+ readonly k: v.OptionalSchema<v.StringSchema<undefined>, never>;
1029
+ readonly key_ops: v.OptionalSchema<v.StringSchema<undefined>, never>;
1030
+ readonly kid: v.OptionalSchema<v.StringSchema<undefined>, never>;
1031
+ readonly oth: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
1032
+ readonly d: v.OptionalSchema<v.StringSchema<undefined>, never>;
1033
+ readonly r: v.OptionalSchema<v.StringSchema<undefined>, never>;
1034
+ readonly t: v.OptionalSchema<v.StringSchema<undefined>, never>;
1035
+ }, undefined>, undefined>, never>;
1036
+ readonly p: v.OptionalSchema<v.StringSchema<undefined>, never>;
1037
+ readonly q: v.OptionalSchema<v.StringSchema<undefined>, never>;
1038
+ readonly qi: v.OptionalSchema<v.StringSchema<undefined>, never>;
1039
+ readonly use: v.OptionalSchema<v.StringSchema<undefined>, never>;
1040
+ readonly x5c: v.OptionalSchema<v.StringSchema<undefined>, never>;
1041
+ readonly x5t: v.OptionalSchema<v.StringSchema<undefined>, never>;
1042
+ readonly 'x5t#S256': v.OptionalSchema<v.StringSchema<undefined>, never>;
1043
+ readonly x5u: v.OptionalSchema<v.StringSchema<undefined>, never>;
1044
+ }, undefined>, never>;
1045
+ readonly jkt: v.OptionalSchema<v.StringSchema<undefined>, never>;
1046
+ }, undefined>, never>;
1047
+ }, undefined>;
1048
+ type TokenIntrospectionResponse = v.InferOutput<typeof vTokenIntrospectionResponse>;
1049
+
1050
+ declare enum PkceCodeChallengeMethod {
1051
+ Plain = "plain",
1052
+ S256 = "S256"
1053
+ }
1054
+ interface CreatePkceReturn {
1055
+ codeVerifier: string;
1056
+ codeChallenge: string;
1057
+ codeChallengeMethod: PkceCodeChallengeMethod;
1058
+ }
1059
+
1060
+ declare const vPreAuthorizedCodeGrantIdentifier: v.LiteralSchema<"urn:ietf:params:oauth:grant-type:pre-authorized_code", undefined>;
1061
+ declare const preAuthorizedCodeGrantIdentifier: "urn:ietf:params:oauth:grant-type:pre-authorized_code";
1062
+ type PreAuthorizedCodeGrantIdentifier = v.InferOutput<typeof vPreAuthorizedCodeGrantIdentifier>;
1063
+ declare const vAuthorizationCodeGrantIdentifier: v.LiteralSchema<"authorization_code", undefined>;
1064
+ declare const authorizationCodeGrantIdentifier: "authorization_code";
1065
+ type AuthorizationCodeGrantIdentifier = v.InferOutput<typeof vAuthorizationCodeGrantIdentifier>;
1066
+ declare const vRefreshTokenGrantIdentifier: v.LiteralSchema<"refresh_token", undefined>;
1067
+ declare const refreshTokenGrantIdentifier: "refresh_token";
1068
+ type RefreshTokenGrantIdentifier = v.InferOutput<typeof vRefreshTokenGrantIdentifier>;
1069
+
1070
+ interface ParsedAccessTokenPreAuthorizedCodeRequestGrant {
1071
+ grantType: PreAuthorizedCodeGrantIdentifier;
1072
+ preAuthorizedCode: string;
1073
+ txCode?: string;
1074
+ }
1075
+ interface ParsedAccessTokenAuthorizationCodeRequestGrant {
1076
+ grantType: AuthorizationCodeGrantIdentifier;
1077
+ code: string;
1078
+ }
1079
+ type ParsedAccessTokenRequestGrant = ParsedAccessTokenPreAuthorizedCodeRequestGrant | ParsedAccessTokenAuthorizationCodeRequestGrant;
1080
+ interface ParseAccessTokenRequestResult {
1081
+ accessTokenRequest: AccessTokenRequest;
1082
+ grant: ParsedAccessTokenRequestGrant;
1083
+ /**
1084
+ * The dpop jwt from the access token request headers
1085
+ */
1086
+ dpopJwt?: string;
1087
+ /**
1088
+ * The pkce code verifier from the access token request
1089
+ */
1090
+ pkceCodeVerifier?: string;
1091
+ }
1092
+ interface ParseAccessTokenRequestOptions {
1093
+ request: RequestLike;
1094
+ /**
1095
+ * The access token request as a JSON object. Your server should decode the
1096
+ * `x-www-url-form-urlencoded` body into an object (e.g. using `bodyParser.urlEncoed()` in express)
1097
+ */
1098
+ accessTokenRequest: Record<string, unknown>;
1099
+ }
1100
+
1101
+ interface VerifyAccessTokenRequestDpop {
1102
+ /**
1103
+ * Whether dpop is required
1104
+ */
1105
+ required?: boolean;
1106
+ /**
1107
+ * The dpop jwt from the access token request
1108
+ */
1109
+ jwt?: string;
1110
+ /**
1111
+ * Allowed dpop signing alg values. If not provided
1112
+ * any alg values are allowed and it's up to the `verifyJwtCallback`
1113
+ * to handle the alg.
1114
+ */
1115
+ allowedSigningAlgs?: string[];
1116
+ }
1117
+ interface VerifyAccessTokenRequestPkce {
1118
+ codeVerifier?: string;
1119
+ codeChallenge: string;
1120
+ codeChallengeMethod: PkceCodeChallengeMethod;
1121
+ }
1122
+ interface VerifyAccessTokenRequestReturn {
1123
+ dpopJwk?: Jwk;
1124
+ }
1125
+ interface VerifyPreAuthorizedCodeAccessTokenRequestOptions {
1126
+ grant: ParsedAccessTokenPreAuthorizedCodeRequestGrant;
1127
+ accessTokenRequest: AccessTokenRequest;
1128
+ request: RequestLike;
1129
+ expectedPreAuthorizedCode: string;
1130
+ expectedTxCode?: string;
1131
+ dpop?: VerifyAccessTokenRequestDpop;
1132
+ pkce?: VerifyAccessTokenRequestPkce;
1133
+ preAuthorizedCodeExpiresAt?: Date;
1134
+ now?: Date;
1135
+ callbacks: Pick<CallbackContext, 'hash' | 'verifyJwt'>;
1136
+ }
1137
+ interface VerifyAuthorizationCodeAccessTokenRequestOptions {
1138
+ grant: ParsedAccessTokenAuthorizationCodeRequestGrant;
1139
+ accessTokenRequest: AccessTokenRequest;
1140
+ request: RequestLike;
1141
+ expectedCode: string;
1142
+ dpop?: VerifyAccessTokenRequestDpop;
1143
+ pkce?: VerifyAccessTokenRequestPkce;
1144
+ codeExpiresAt?: Date;
1145
+ now?: Date;
1146
+ callbacks: Pick<CallbackContext, 'hash' | 'verifyJwt'>;
1147
+ }
1148
+
1149
+ interface RetrieveAccessTokenReturn {
1150
+ accessTokenResponse: AccessTokenResponse;
1151
+ dpop?: RequestDpopOptions;
1152
+ }
1153
+ interface RetrieveAccessTokenBaseOptions {
1154
+ /**
1155
+ * Authorization server to request the access token from
1156
+ */
1157
+ authorizationServerMetadata: AuthorizationServerMetadata;
1158
+ /**
1159
+ * Callbacks to use for requesting access token
1160
+ */
1161
+ callbacks: Pick<CallbackContext, 'fetch' | 'generateRandom' | 'hash' | 'signJwt'>;
1162
+ /**
1163
+ * The resource to which access is being requested. This can help the authorization
1164
+ * server in determining the resource server to handle the authorization request for
1165
+ */
1166
+ resource?: string;
1167
+ /**
1168
+ * Dpop parameters for including a dpop in the access token request. The request will automatically
1169
+ * be retried if the server responds with a 'use_dpop_nonce' header.
1170
+ *
1171
+ * If provided but 'dpop_signing_alg_values_supported' is not available in the authorization server
1172
+ * metadata, or the 'alg' value does not match an error will be thrown.
1173
+ */
1174
+ dpop?: RequestDpopOptions;
1175
+ /**
1176
+ * If client attestation needs to be included in the request.
1177
+ */
1178
+ clientAttestation?: RequestClientAttestationOptions;
1179
+ }
1180
+ interface RetrievePreAuthorizedCodeAccessTokenOptions extends RetrieveAccessTokenBaseOptions {
1181
+ preAuthorizedCode: string;
1182
+ txCode?: string;
1183
+ /**
1184
+ * Additional payload to include in the access token request. Items will be encoded and sent
1185
+ * using x-www-form-urlencoded format. Nested items (JSON) will be stringified and url encoded.
1186
+ */
1187
+ additionalRequestPayload?: Record<string, unknown>;
1188
+ }
1189
+ interface RetrieveAuthorizationCodeAccessTokenOptions extends RetrieveAccessTokenBaseOptions {
1190
+ /**
1191
+ * PKCE Code verifier that was used in the authorization request.
1192
+ */
1193
+ pkceCodeVerifier?: string;
1194
+ /**
1195
+ * The authorization code
1196
+ */
1197
+ authorizationCode: string;
1198
+ /**
1199
+ * Redirect uri to include in the access token request. Only required
1200
+ * if the redirect uri was present in the authorization request.
1201
+ */
1202
+ redirectUri?: string;
1203
+ /**
1204
+ * Additional payload to include in the access token request. Items will be encoded and sent
1205
+ * using x-www-form-urlencoded format. Nested items (JSON) will be stringified and url encoded.
1206
+ */
1207
+ additionalRequestPayload?: Record<string, unknown>;
1208
+ }
1209
+ interface RetrieveRefreshTokenAccessTokenOptions extends RetrieveAccessTokenBaseOptions {
1210
+ /**
1211
+ * The refresh token
1212
+ */
1213
+ refreshToken: string;
1214
+ /**
1215
+ * Additional payload to include in the access token request. Items will be encoded and sent
1216
+ * using x-www-form-urlencoded format. Nested items (JSON) will be stringified and url encoded.
1217
+ */
1218
+ additionalRequestPayload?: Record<string, unknown>;
1219
+ }
1220
+
1221
+ interface CreateAuthorizationRequestUrlOptions {
1222
+ /**
1223
+ * Callback context mostly for crypto related functionality
1224
+ */
1225
+ callbacks: Pick<CallbackContext, 'fetch' | 'hash' | 'generateRandom' | 'signJwt'>;
1226
+ /**
1227
+ * Metadata of the authorization server for which to create the authorization request url
1228
+ */
1229
+ authorizationServerMetadata: AuthorizationServerMetadata;
1230
+ /**
1231
+ * The client id to use for the authorization request
1232
+ */
1233
+ clientId: string;
1234
+ /**
1235
+ * Scope to request for the authorization request
1236
+ */
1237
+ scope?: string;
1238
+ /**
1239
+ * The resource to which access is being requested. This can help the authorization
1240
+ * server in determining the resource server to handle the authorization request for
1241
+ */
1242
+ resource?: string;
1243
+ /**
1244
+ * Redirect uri to include in the authorization request
1245
+ */
1246
+ redirectUri?: string;
1247
+ /**
1248
+ * Additional payload to include in the authorization request. Items will be encoded and sent
1249
+ * using x-www-form-urlencoded format. Nested items (JSON) will be stringified and url encoded.
1250
+ */
1251
+ additionalRequestPayload?: Record<string, unknown>;
1252
+ /**
1253
+ * Code verifier to use for pkce. If not provided a value will generated when pkce is supported
1254
+ */
1255
+ pkceCodeVerifier?: string;
1256
+ /**
1257
+ * If client attestation needs to be included in the request.
1258
+ *
1259
+ * Will ONLY be used if PAR is used.
1260
+ */
1261
+ clientAttestation?: RequestClientAttestationOptions;
1262
+ /**
1263
+ * DPoP options
1264
+ *
1265
+ * If PAR is not used only the `dpop_jkt` property will be included in the request
1266
+ */
1267
+ dpop?: RequestDpopOptions;
1268
+ }
1269
+
1270
+ interface ResourceRequestOptions {
1271
+ /**
1272
+ * DPoP options
1273
+ */
1274
+ dpop?: RequestDpopOptions & {
1275
+ /**
1276
+ * Whether to retry the request if the server responds with an error indicating
1277
+ * the request should be retried with a server provided dpop nonce
1278
+ *
1279
+ * @default true
1280
+ */
1281
+ retryWithNonce?: boolean;
1282
+ };
1283
+ /**
1284
+ * Callbacks
1285
+ */
1286
+ callbacks: Pick<CallbackContext, 'fetch' | 'generateRandom' | 'signJwt' | 'hash'>;
1287
+ /**
1288
+ * Access token
1289
+ */
1290
+ accessToken: string;
1291
+ url: string;
1292
+ requestOptions: FetchRequestInit;
1293
+ }
1294
+ interface ResourceRequestResponseBase {
1295
+ ok: boolean;
1296
+ response: FetchResponse;
1297
+ /**
1298
+ * If the response included a dpop nonce to be used in subsequent requests
1299
+ */
1300
+ dpop?: {
1301
+ nonce: string;
1302
+ };
1303
+ }
1304
+ interface ResourceRequestResponseOk extends ResourceRequestResponseBase {
1305
+ ok: true;
1306
+ }
1307
+ interface ResourceRequestResponseNotOk extends ResourceRequestResponseBase {
1308
+ ok: false;
1309
+ /**
1310
+ * If a WWW-Authenticate was included in the headers of the response
1311
+ * they will be parsed and added here.
1312
+ */
1313
+ wwwAuthenticate?: WwwAuthenticateHeaderChallenge[];
1314
+ }
1315
+ declare function resourceRequest(options: ResourceRequestOptions): Promise<ResourceRequestResponseOk | ResourceRequestResponseNotOk>;
1316
+
1317
+ interface VerifyResourceRequestOptions {
1318
+ /**
1319
+ * The incoming request
1320
+ */
1321
+ request: RequestLike;
1322
+ /**
1323
+ * Identifier for the resource server, will be matched with the `aud` value of the access token.
1324
+ */
1325
+ resourceServer: string;
1326
+ /**
1327
+ * Callbacks for verification of the access token.
1328
+ */
1329
+ callbacks: Pick<CallbackContext, 'verifyJwt' | 'hash' | 'clientAuthentication' | 'fetch'>;
1330
+ /**
1331
+ * allowed auth schems for the access token. If not provided
1332
+ * all supported authentication schemes are allowed.
1333
+ */
1334
+ allowedAuthenticationSchemes?: SupportedAuthenticationScheme[];
1335
+ /**
1336
+ * List of authorization servers that this resource endpoint supports
1337
+ */
1338
+ authorizationServers: AuthorizationServerMetadata[];
1339
+ now?: Date;
1340
+ }
1341
+ declare function verifyResourceRequest(options: VerifyResourceRequestOptions): Promise<{
1342
+ tokenPayload: ({
1343
+ sub: string;
1344
+ iss: string;
1345
+ aud: string;
1346
+ iat: number;
1347
+ exp: number;
1348
+ jti: string;
1349
+ scope?: string | undefined;
1350
+ client_id?: string | undefined;
1351
+ nbf?: number | undefined;
1352
+ nonce?: string | undefined;
1353
+ cnf?: ({
1354
+ jwk?: ({
1355
+ kty: string;
1356
+ crv?: string | undefined;
1357
+ x?: string | undefined;
1358
+ y?: string | undefined;
1359
+ e?: string | undefined;
1360
+ n?: string | undefined;
1361
+ alg?: string | undefined;
1362
+ d?: string | undefined;
1363
+ dp?: string | undefined;
1364
+ dq?: string | undefined;
1365
+ ext?: boolean | undefined;
1366
+ k?: string | undefined;
1367
+ key_ops?: string | undefined;
1368
+ kid?: string | undefined;
1369
+ oth?: ({
1370
+ d?: string | undefined;
1371
+ r?: string | undefined;
1372
+ t?: string | undefined;
1373
+ } & {
1374
+ [key: string]: unknown;
1375
+ })[] | undefined;
1376
+ p?: string | undefined;
1377
+ q?: string | undefined;
1378
+ qi?: string | undefined;
1379
+ use?: string | undefined;
1380
+ x5c?: string | undefined;
1381
+ x5t?: string | undefined;
1382
+ 'x5t#S256'?: string | undefined;
1383
+ x5u?: string | undefined;
1384
+ } & {
1385
+ [key: string]: unknown;
1386
+ }) | undefined;
1387
+ jkt?: string | undefined;
1388
+ } & {
1389
+ [key: string]: unknown;
1390
+ }) | undefined;
1391
+ status?: ({} & {
1392
+ [key: string]: unknown;
1393
+ }) | undefined;
1394
+ } & {
1395
+ [key: string]: unknown;
1396
+ }) | ({
1397
+ active: boolean;
1398
+ sub?: string | undefined;
1399
+ scope?: string | undefined;
1400
+ token_type?: string | undefined;
1401
+ client_id?: string | undefined;
1402
+ iss?: string | undefined;
1403
+ aud?: string | undefined;
1404
+ iat?: number | undefined;
1405
+ exp?: number | undefined;
1406
+ nbf?: number | undefined;
1407
+ jti?: string | undefined;
1408
+ cnf?: ({
1409
+ jwk?: ({
1410
+ kty: string;
1411
+ crv?: string | undefined;
1412
+ x?: string | undefined;
1413
+ y?: string | undefined;
1414
+ e?: string | undefined;
1415
+ n?: string | undefined;
1416
+ alg?: string | undefined;
1417
+ d?: string | undefined;
1418
+ dp?: string | undefined;
1419
+ dq?: string | undefined;
1420
+ ext?: boolean | undefined;
1421
+ k?: string | undefined;
1422
+ key_ops?: string | undefined;
1423
+ kid?: string | undefined;
1424
+ oth?: ({
1425
+ d?: string | undefined;
1426
+ r?: string | undefined;
1427
+ t?: string | undefined;
1428
+ } & {
1429
+ [key: string]: unknown;
1430
+ })[] | undefined;
1431
+ p?: string | undefined;
1432
+ q?: string | undefined;
1433
+ qi?: string | undefined;
1434
+ use?: string | undefined;
1435
+ x5c?: string | undefined;
1436
+ x5t?: string | undefined;
1437
+ 'x5t#S256'?: string | undefined;
1438
+ x5u?: string | undefined;
1439
+ } & {
1440
+ [key: string]: unknown;
1441
+ }) | undefined;
1442
+ jkt?: string | undefined;
1443
+ } & {
1444
+ [key: string]: unknown;
1445
+ }) | undefined;
1446
+ username?: string | undefined;
1447
+ } & {
1448
+ [key: string]: unknown;
1449
+ });
1450
+ dpopJwk: ({
1451
+ kty: string;
1452
+ crv?: string | undefined;
1453
+ x?: string | undefined;
1454
+ y?: string | undefined;
1455
+ e?: string | undefined;
1456
+ n?: string | undefined;
1457
+ alg?: string | undefined;
1458
+ d?: string | undefined;
1459
+ dp?: string | undefined;
1460
+ dq?: string | undefined;
1461
+ ext?: boolean | undefined;
1462
+ k?: string | undefined;
1463
+ key_ops?: string | undefined;
1464
+ kid?: string | undefined;
1465
+ oth?: ({
1466
+ d?: string | undefined;
1467
+ r?: string | undefined;
1468
+ t?: string | undefined;
1469
+ } & {
1470
+ [key: string]: unknown;
1471
+ })[] | undefined;
1472
+ p?: string | undefined;
1473
+ q?: string | undefined;
1474
+ qi?: string | undefined;
1475
+ use?: string | undefined;
1476
+ x5c?: string | undefined;
1477
+ x5t?: string | undefined;
1478
+ 'x5t#S256'?: string | undefined;
1479
+ x5u?: string | undefined;
1480
+ } & {
1481
+ [key: string]: unknown;
1482
+ }) | undefined;
1483
+ scheme: any;
1484
+ accessToken: any;
1485
+ authorizationServer: string;
1486
+ }>;
1487
+
1488
+ interface CreateAccessTokenOptions {
1489
+ callbacks: Pick<CallbackContext, 'signJwt' | 'generateRandom' | 'hash'>;
1490
+ /**
1491
+ * public dpop jwk key. Will be encoded as jwk thubmprint in the `cnf.jkt` claim.
1492
+ */
1493
+ dpopJwk?: Jwk;
1494
+ /**
1495
+ * scope of the access token. If the authorization request included scopes
1496
+ * they should be added to the access token as well
1497
+ */
1498
+ scope?: string;
1499
+ /**
1500
+ * Client id to which the access token is bound.
1501
+ * Can be undefined in case of anonymous access using pre authorized code flow
1502
+ */
1503
+ clientId?: string;
1504
+ /**
1505
+ * The authorization server that issues the access token
1506
+ */
1507
+ authorizationServer: string;
1508
+ /**
1509
+ * Signer of the access token
1510
+ */
1511
+ signer: JwtSigner;
1512
+ /**
1513
+ * Number of seconds after which the token will expire
1514
+ */
1515
+ expiresInSeconds: number;
1516
+ /**
1517
+ * The audience of the access token. Should be the `resource` if included in the authorization request
1518
+ */
1519
+ audience: string;
1520
+ /**
1521
+ * The subject of the access token. When a resource owner is involved,
1522
+ * it should be an identifier for the resource owner.
1523
+ */
1524
+ subject: string;
1525
+ /**
1526
+ * Date that should be used as now. If not provided current date will be used.
1527
+ */
1528
+ now?: Date;
1529
+ /**
1530
+ * Additional payload claims to include in the access token JWT.
1531
+ * Will override existing claims so you can override default behaviour, but be careful.
1532
+ */
1533
+ additionalPayload?: Record<string, unknown>;
1534
+ }
1535
+
1536
+ interface CreateAccessTokenResponseOptions {
1537
+ callbacks: Pick<CallbackContext, 'signJwt' | 'generateRandom' | 'hash'>;
1538
+ /**
1539
+ * The access token
1540
+ */
1541
+ accessToken: string;
1542
+ /**
1543
+ * The type of token. Should be DPoP if the access token
1544
+ * is bound to a dpop key
1545
+ */
1546
+ tokenType: 'DPoP' | 'Bearer' | (string & {});
1547
+ /**
1548
+ * Number of seconds after which the access tokens expires.
1549
+ */
1550
+ expiresInSeconds: number;
1551
+ /**
1552
+ * New cNonce value
1553
+ */
1554
+ cNonce?: string;
1555
+ cNonceExpiresIn?: number;
1556
+ /**
1557
+ * Additional payload to include in the access token response.
1558
+ *
1559
+ * Will be applied after default payload to allow overriding over values, but be careful.
1560
+ */
1561
+ additionalPayload?: Record<string, unknown>;
1562
+ }
1563
+
1564
+ interface CreateAuthorizationChallengeResponseOptions {
1565
+ /**
1566
+ * The authorization code
1567
+ */
1568
+ authorizationCode: string;
1569
+ /**
1570
+ * Additional payload to include in the authorization challenge response.
1571
+ */
1572
+ additionalPayload?: Record<string, unknown>;
1573
+ }
1574
+ interface CreateAuthorizationChallengeErrorResponseOptions {
1575
+ /**
1576
+ * Auth session identifier for the authorization challenge. The client MUST include this
1577
+ * in subsequent requests to the authorization challenge endpoint.
1578
+ */
1579
+ authSession?: string;
1580
+ /**
1581
+ * The presentation during issuance error.
1582
+ *
1583
+ * Error codes specific to authorization challenge are:
1584
+ * - @see Oauth2ErrorCodes.RedirectToWeb
1585
+ * - @see Oauth2ErrorCodes.InvalidSession
1586
+ * - @see Oauth2ErrorCodes.InsufficientAuthorization
1587
+ *
1588
+ * If you want to require presentation of a
1589
+ */
1590
+ error: StringWithAutoCompletion<Oauth2ErrorCodes>;
1591
+ /**
1592
+ * Optional error description
1593
+ */
1594
+ errorDescription?: string;
1595
+ /**
1596
+ * OpenID4VP authorization request url that must be completed before authorization
1597
+ * can be granted
1598
+ *
1599
+ * Should be combined with `error` @see Oauth2ErrorCodes.InsufficientAuthorization
1600
+ */
1601
+ presentation?: string;
1602
+ /**
1603
+ * Optional PAR request uri, allowing the authorization challenge request to be treated
1604
+ * as a succesfull pushed authorization request.
1605
+ *
1606
+ * Should be combined with `error` @see Oauth2ErrorCodes.RedirectToWeb
1607
+ */
1608
+ requestUri?: string;
1609
+ /**
1610
+ * Duration is seconds after which the `requestUri` parameter will expire. Should only be included
1611
+ * if the `requestUri` is also included, and has no meaning otherwise
1612
+ */
1613
+ expiresIn?: number;
1614
+ /**
1615
+ * Additional payload to include in the authorization challenge error response.
1616
+ */
1617
+ additionalPayload?: Record<string, unknown>;
1618
+ }
1619
+
1620
+ interface ParseAuthorizationChallengeRequestOptions {
1621
+ authorizationChallengeRequest: unknown;
1622
+ }
1623
+
1624
+ interface Oauth2AuthorizationServerOptions {
1625
+ /**
1626
+ * Callbacks required for the oauth2 authorization server
1627
+ */
1628
+ callbacks: CallbackContext;
1629
+ }
1630
+ declare class Oauth2AuthorizationServer {
1631
+ private options;
1632
+ constructor(options: Oauth2AuthorizationServerOptions);
1633
+ createAuthorizationServerMetadata(authorizationServerMetadata: AuthorizationServerMetadata): {
1634
+ issuer: string;
1635
+ token_endpoint: string;
1636
+ token_endpoint_auth_methods_supported?: string[] | undefined;
1637
+ authorization_endpoint?: string | undefined;
1638
+ jwks_uri?: string | undefined;
1639
+ code_challenge_methods_supported?: string[] | undefined;
1640
+ dpop_signing_alg_values_supported?: string[] | undefined;
1641
+ require_pushed_authorization_requests?: boolean | undefined;
1642
+ pushed_authorization_request_endpoint?: string | undefined;
1643
+ introspection_endpoint?: string | undefined;
1644
+ introspection_endpoint_auth_methods_supported?: string[] | undefined;
1645
+ introspection_endpoint_auth_signing_alg_values_supported?: string[] | undefined;
1646
+ authorization_challenge_endpoint?: string | undefined;
1647
+ 'pre-authorized_grant_anonymous_access_supported'?: boolean | undefined;
1648
+ } & {
1649
+ [key: string]: unknown;
1650
+ };
1651
+ /**
1652
+ * Parse access token request and extract the grant specific properties.
1653
+ *
1654
+ * If something goes wrong, such as the grant is not supported, missing parameters, etc,
1655
+ * it will throw `Oauth2ServerErrorResponseError` containing an error response object
1656
+ * that can be returned to the client.
1657
+ */
1658
+ parseAccessTokenRequest(options: ParseAccessTokenRequestOptions): ParseAccessTokenRequestResult;
1659
+ verifyPreAuthorizedCodeAccessTokenRequest(options: Omit<VerifyPreAuthorizedCodeAccessTokenRequestOptions, 'callbacks'>): Promise<VerifyAccessTokenRequestReturn>;
1660
+ verifyAuthorizationCodeAccessTokenRequest(options: Omit<VerifyAuthorizationCodeAccessTokenRequestOptions, 'callbacks'>): Promise<VerifyAccessTokenRequestReturn>;
1661
+ /**
1662
+ * Create an access token response.
1663
+ *
1664
+ * The `sub` claim can be used to identify the resource owner is subsequent requests.
1665
+ * For pre-auth flow this can be the pre-authorized_code but there are no requirements
1666
+ * on the value.
1667
+ */
1668
+ createAccessTokenResponse(options: Pick<CreateAccessTokenOptions, 'expiresInSeconds' | 'scope' | 'clientId' | 'audience' | 'signer' | 'dpopJwk' | 'authorizationServer' | 'now' | 'subject'> & Pick<CreateAccessTokenResponseOptions, 'cNonce' | 'cNonceExpiresIn'> & {
1669
+ additionalAccessTokenPayload?: CreateAccessTokenOptions['additionalPayload'];
1670
+ additionalAccessTokenResponsePayload?: CreateAccessTokenResponseOptions['additionalPayload'];
1671
+ }): Promise<{
1672
+ access_token: string;
1673
+ token_type: string;
1674
+ refresh_token?: string | undefined;
1675
+ expires_in?: number | undefined;
1676
+ scope?: string | undefined;
1677
+ state?: string | undefined;
1678
+ c_nonce?: string | undefined;
1679
+ c_nonce_expires_in?: number | undefined;
1680
+ authorization_details?: ({} & {
1681
+ [key: string]: unknown;
1682
+ })[] | undefined;
1683
+ } & {
1684
+ [key: string]: unknown;
1685
+ }>;
1686
+ /**
1687
+ * Parse an authorization challenge request
1688
+ */
1689
+ parseAuthorizationChallengeRequest(options: ParseAuthorizationChallengeRequestOptions): {
1690
+ authorizationChallengeRequest: {
1691
+ redirect_uri?: string | undefined;
1692
+ resource?: string | undefined;
1693
+ scope?: string | undefined;
1694
+ client_id?: string | undefined;
1695
+ issuer_state?: string | undefined;
1696
+ dpop_jkt?: string | undefined;
1697
+ code_challenge?: string | undefined;
1698
+ code_challenge_method?: string | undefined;
1699
+ auth_session?: string | undefined;
1700
+ presentation_during_issuance_session?: string | undefined;
1701
+ } & {
1702
+ [key: string]: unknown;
1703
+ };
1704
+ };
1705
+ createAuthorizationChallengeResponse(options: CreateAuthorizationChallengeResponseOptions): {
1706
+ authorizationChallengeResponse: {
1707
+ authorization_code: string;
1708
+ } & {
1709
+ [key: string]: unknown;
1710
+ };
1711
+ };
1712
+ /**
1713
+ * Create an authorization challenge error response indicating presentation of credenitals
1714
+ * using OpenID4VP is required before authorization can be granted.
1715
+ *
1716
+ * The `presentation` parameter should be an OpenID4VP authorization request url.
1717
+ * The `authSession` should be used to track the session
1718
+ */
1719
+ createAuthorizationChallengePresentationErrorResponse(options: Pick<CreateAuthorizationChallengeErrorResponseOptions, 'errorDescription' | 'additionalPayload'> & Required<Pick<CreateAuthorizationChallengeErrorResponseOptions, 'authSession' | 'presentation'>>): {
1720
+ error: string;
1721
+ error_description?: string | undefined;
1722
+ error_uri?: string | undefined;
1723
+ expires_in?: number | undefined;
1724
+ request_uri?: string | undefined;
1725
+ auth_session?: string | undefined;
1726
+ presentation?: string | undefined;
1727
+ } & {
1728
+ [key: string]: unknown;
1729
+ };
1730
+ createAuthorizationChallengeErrorResponse(options: CreateAuthorizationChallengeErrorResponseOptions): {
1731
+ error: string;
1732
+ error_description?: string | undefined;
1733
+ error_uri?: string | undefined;
1734
+ expires_in?: number | undefined;
1735
+ request_uri?: string | undefined;
1736
+ auth_session?: string | undefined;
1737
+ presentation?: string | undefined;
1738
+ } & {
1739
+ [key: string]: unknown;
1740
+ };
1741
+ verifyClientAttestation({ authorizationServer, headers, }: {
1742
+ authorizationServer: string;
1743
+ headers: FetchHeaders;
1744
+ }): Promise<{
1745
+ clientAttestation: {
1746
+ header: {
1747
+ alg: string;
1748
+ typ: "oauth-client-attestation+jwt";
1749
+ kid?: string | undefined;
1750
+ x5c?: string[] | undefined;
1751
+ jwk?: ({
1752
+ kty: string;
1753
+ crv?: string | undefined;
1754
+ x?: string | undefined;
1755
+ y?: string | undefined;
1756
+ e?: string | undefined;
1757
+ n?: string | undefined;
1758
+ alg?: string | undefined;
1759
+ d?: string | undefined;
1760
+ dp?: string | undefined;
1761
+ dq?: string | undefined;
1762
+ ext?: boolean | undefined;
1763
+ k?: string | undefined;
1764
+ key_ops?: string | undefined;
1765
+ kid?: string | undefined;
1766
+ oth?: ({
1767
+ d?: string | undefined;
1768
+ r?: string | undefined;
1769
+ t?: string | undefined;
1770
+ } & {
1771
+ [key: string]: unknown;
1772
+ })[] | undefined;
1773
+ p?: string | undefined;
1774
+ q?: string | undefined;
1775
+ qi?: string | undefined;
1776
+ use?: string | undefined;
1777
+ x5c?: string | undefined;
1778
+ x5t?: string | undefined;
1779
+ 'x5t#S256'?: string | undefined;
1780
+ x5u?: string | undefined;
1781
+ } & {
1782
+ [key: string]: unknown;
1783
+ }) | undefined;
1784
+ trust_chain?: string[] | undefined;
1785
+ } & {
1786
+ [key: string]: unknown;
1787
+ };
1788
+ payload: {
1789
+ sub: string;
1790
+ iss: string;
1791
+ exp: number;
1792
+ cnf: {
1793
+ jwk: {
1794
+ kty: string;
1795
+ crv?: string | undefined;
1796
+ x?: string | undefined;
1797
+ y?: string | undefined;
1798
+ e?: string | undefined;
1799
+ n?: string | undefined;
1800
+ alg?: string | undefined;
1801
+ d?: string | undefined;
1802
+ dp?: string | undefined;
1803
+ dq?: string | undefined;
1804
+ ext?: boolean | undefined;
1805
+ k?: string | undefined;
1806
+ key_ops?: string | undefined;
1807
+ kid?: string | undefined;
1808
+ oth?: ({
1809
+ d?: string | undefined;
1810
+ r?: string | undefined;
1811
+ t?: string | undefined;
1812
+ } & {
1813
+ [key: string]: unknown;
1814
+ })[] | undefined;
1815
+ p?: string | undefined;
1816
+ q?: string | undefined;
1817
+ qi?: string | undefined;
1818
+ use?: string | undefined;
1819
+ x5c?: string | undefined;
1820
+ x5t?: string | undefined;
1821
+ 'x5t#S256'?: string | undefined;
1822
+ x5u?: string | undefined;
1823
+ } & {
1824
+ [key: string]: unknown;
1825
+ };
1826
+ key_type?: string | undefined;
1827
+ user_authentication?: string | undefined;
1828
+ } & {
1829
+ [key: string]: unknown;
1830
+ };
1831
+ aud?: string | undefined;
1832
+ iat?: number | undefined;
1833
+ nbf?: number | undefined;
1834
+ nonce?: string | undefined;
1835
+ jti?: string | undefined;
1836
+ status?: ({} & {
1837
+ [key: string]: unknown;
1838
+ }) | undefined;
1839
+ aal?: string | undefined;
1840
+ } & {
1841
+ [key: string]: unknown;
1842
+ };
1843
+ signer: JwtSignerWithJwk;
1844
+ };
1845
+ clientAttestationPop: {
1846
+ header: {
1847
+ alg: string;
1848
+ typ: "oauth-client-attestation-pop+jwt";
1849
+ kid?: string | undefined;
1850
+ x5c?: string[] | undefined;
1851
+ jwk?: ({
1852
+ kty: string;
1853
+ crv?: string | undefined;
1854
+ x?: string | undefined;
1855
+ y?: string | undefined;
1856
+ e?: string | undefined;
1857
+ n?: string | undefined;
1858
+ alg?: string | undefined;
1859
+ d?: string | undefined;
1860
+ dp?: string | undefined;
1861
+ dq?: string | undefined;
1862
+ ext?: boolean | undefined;
1863
+ k?: string | undefined;
1864
+ key_ops?: string | undefined;
1865
+ kid?: string | undefined;
1866
+ oth?: ({
1867
+ d?: string | undefined;
1868
+ r?: string | undefined;
1869
+ t?: string | undefined;
1870
+ } & {
1871
+ [key: string]: unknown;
1872
+ })[] | undefined;
1873
+ p?: string | undefined;
1874
+ q?: string | undefined;
1875
+ qi?: string | undefined;
1876
+ use?: string | undefined;
1877
+ x5c?: string | undefined;
1878
+ x5t?: string | undefined;
1879
+ 'x5t#S256'?: string | undefined;
1880
+ x5u?: string | undefined;
1881
+ } & {
1882
+ [key: string]: unknown;
1883
+ }) | undefined;
1884
+ trust_chain?: string[] | undefined;
1885
+ } & {
1886
+ [key: string]: unknown;
1887
+ };
1888
+ payload: {
1889
+ iss: string;
1890
+ aud: string;
1891
+ exp: number;
1892
+ jti: string;
1893
+ iat?: number | undefined;
1894
+ nbf?: number | undefined;
1895
+ nonce?: string | undefined;
1896
+ cnf?: ({
1897
+ jwk?: ({
1898
+ kty: string;
1899
+ crv?: string | undefined;
1900
+ x?: string | undefined;
1901
+ y?: string | undefined;
1902
+ e?: string | undefined;
1903
+ n?: string | undefined;
1904
+ alg?: string | undefined;
1905
+ d?: string | undefined;
1906
+ dp?: string | undefined;
1907
+ dq?: string | undefined;
1908
+ ext?: boolean | undefined;
1909
+ k?: string | undefined;
1910
+ key_ops?: string | undefined;
1911
+ kid?: string | undefined;
1912
+ oth?: ({
1913
+ d?: string | undefined;
1914
+ r?: string | undefined;
1915
+ t?: string | undefined;
1916
+ } & {
1917
+ [key: string]: unknown;
1918
+ })[] | undefined;
1919
+ p?: string | undefined;
1920
+ q?: string | undefined;
1921
+ qi?: string | undefined;
1922
+ use?: string | undefined;
1923
+ x5c?: string | undefined;
1924
+ x5t?: string | undefined;
1925
+ 'x5t#S256'?: string | undefined;
1926
+ x5u?: string | undefined;
1927
+ } & {
1928
+ [key: string]: unknown;
1929
+ }) | undefined;
1930
+ jkt?: string | undefined;
1931
+ } & {
1932
+ [key: string]: unknown;
1933
+ }) | undefined;
1934
+ status?: ({} & {
1935
+ [key: string]: unknown;
1936
+ }) | undefined;
1937
+ } & {
1938
+ [key: string]: unknown;
1939
+ };
1940
+ signer: JwtSignerWithJwk;
1941
+ };
1942
+ }>;
1943
+ }
1944
+
1945
+ interface Oauth2ResourceServerOptions {
1946
+ /**
1947
+ * Callbacks required for the oauth2 resource server
1948
+ */
1949
+ callbacks: Pick<CallbackContext, 'verifyJwt' | 'hash' | 'clientAuthentication' | 'fetch'>;
1950
+ }
1951
+ declare class Oauth2ResourceServer {
1952
+ private options;
1953
+ constructor(options: Oauth2ResourceServerOptions);
1954
+ verifyResourceRequest(options: Omit<VerifyResourceRequestOptions, 'callbacks'>): Promise<{
1955
+ tokenPayload: ({
1956
+ sub: string;
1957
+ iss: string;
1958
+ aud: string;
1959
+ iat: number;
1960
+ exp: number;
1961
+ jti: string;
1962
+ scope?: string | undefined;
1963
+ client_id?: string | undefined;
1964
+ nbf?: number | undefined;
1965
+ nonce?: string | undefined;
1966
+ cnf?: ({
1967
+ jwk?: ({
1968
+ kty: string;
1969
+ crv?: string | undefined;
1970
+ x?: string | undefined;
1971
+ y?: string | undefined;
1972
+ e?: string | undefined;
1973
+ n?: string | undefined;
1974
+ alg?: string | undefined;
1975
+ d?: string | undefined;
1976
+ dp?: string | undefined;
1977
+ dq?: string | undefined;
1978
+ ext?: boolean | undefined;
1979
+ k?: string | undefined;
1980
+ key_ops?: string | undefined;
1981
+ kid?: string | undefined;
1982
+ oth?: ({
1983
+ d?: string | undefined;
1984
+ r?: string | undefined;
1985
+ t?: string | undefined;
1986
+ } & {
1987
+ [key: string]: unknown;
1988
+ })[] | undefined;
1989
+ p?: string | undefined;
1990
+ q?: string | undefined;
1991
+ qi?: string | undefined;
1992
+ use?: string | undefined;
1993
+ x5c?: string | undefined;
1994
+ x5t?: string | undefined;
1995
+ 'x5t#S256'?: string | undefined;
1996
+ x5u?: string | undefined;
1997
+ } & {
1998
+ [key: string]: unknown;
1999
+ }) | undefined;
2000
+ jkt?: string | undefined;
2001
+ } & {
2002
+ [key: string]: unknown;
2003
+ }) | undefined;
2004
+ status?: ({} & {
2005
+ [key: string]: unknown;
2006
+ }) | undefined;
2007
+ } & {
2008
+ [key: string]: unknown;
2009
+ }) | ({
2010
+ active: boolean;
2011
+ sub?: string | undefined;
2012
+ scope?: string | undefined;
2013
+ token_type?: string | undefined;
2014
+ client_id?: string | undefined;
2015
+ iss?: string | undefined;
2016
+ aud?: string | undefined;
2017
+ iat?: number | undefined;
2018
+ exp?: number | undefined;
2019
+ nbf?: number | undefined;
2020
+ jti?: string | undefined;
2021
+ cnf?: ({
2022
+ jwk?: ({
2023
+ kty: string;
2024
+ crv?: string | undefined;
2025
+ x?: string | undefined;
2026
+ y?: string | undefined;
2027
+ e?: string | undefined;
2028
+ n?: string | undefined;
2029
+ alg?: string | undefined;
2030
+ d?: string | undefined;
2031
+ dp?: string | undefined;
2032
+ dq?: string | undefined;
2033
+ ext?: boolean | undefined;
2034
+ k?: string | undefined;
2035
+ key_ops?: string | undefined;
2036
+ kid?: string | undefined;
2037
+ oth?: ({
2038
+ d?: string | undefined;
2039
+ r?: string | undefined;
2040
+ t?: string | undefined;
2041
+ } & {
2042
+ [key: string]: unknown;
2043
+ })[] | undefined;
2044
+ p?: string | undefined;
2045
+ q?: string | undefined;
2046
+ qi?: string | undefined;
2047
+ use?: string | undefined;
2048
+ x5c?: string | undefined;
2049
+ x5t?: string | undefined;
2050
+ 'x5t#S256'?: string | undefined;
2051
+ x5u?: string | undefined;
2052
+ } & {
2053
+ [key: string]: unknown;
2054
+ }) | undefined;
2055
+ jkt?: string | undefined;
2056
+ } & {
2057
+ [key: string]: unknown;
2058
+ }) | undefined;
2059
+ username?: string | undefined;
2060
+ } & {
2061
+ [key: string]: unknown;
2062
+ });
2063
+ dpopJwk: ({
2064
+ kty: string;
2065
+ crv?: string | undefined;
2066
+ x?: string | undefined;
2067
+ y?: string | undefined;
2068
+ e?: string | undefined;
2069
+ n?: string | undefined;
2070
+ alg?: string | undefined;
2071
+ d?: string | undefined;
2072
+ dp?: string | undefined;
2073
+ dq?: string | undefined;
2074
+ ext?: boolean | undefined;
2075
+ k?: string | undefined;
2076
+ key_ops?: string | undefined;
2077
+ kid?: string | undefined;
2078
+ oth?: ({
2079
+ d?: string | undefined;
2080
+ r?: string | undefined;
2081
+ t?: string | undefined;
2082
+ } & {
2083
+ [key: string]: unknown;
2084
+ })[] | undefined;
2085
+ p?: string | undefined;
2086
+ q?: string | undefined;
2087
+ qi?: string | undefined;
2088
+ use?: string | undefined;
2089
+ x5c?: string | undefined;
2090
+ x5t?: string | undefined;
2091
+ 'x5t#S256'?: string | undefined;
2092
+ x5u?: string | undefined;
2093
+ } & {
2094
+ [key: string]: unknown;
2095
+ }) | undefined;
2096
+ scheme: any;
2097
+ accessToken: any;
2098
+ authorizationServer: string;
2099
+ }>;
2100
+ }
2101
+
2102
+ interface SendAuthorizationChallengeRequestOptions {
2103
+ /**
2104
+ * Callback context
2105
+ */
2106
+ callbacks: Pick<CallbackContext, 'fetch' | 'hash' | 'generateRandom' | 'signJwt'>;
2107
+ /**
2108
+ * Metadata of the authorization server where to perform the authorization challenge
2109
+ */
2110
+ authorizationServerMetadata: AuthorizationServerMetadata;
2111
+ /**
2112
+ * Previously established auth session
2113
+ */
2114
+ authSession?: string;
2115
+ /**
2116
+ * The client id to use for the authorization challenge request
2117
+ */
2118
+ clientId?: string;
2119
+ /**
2120
+ * Scope to request for the authorization challenge request
2121
+ */
2122
+ scope?: string;
2123
+ /**
2124
+ * The resource to which access is being requested. This can help the authorization
2125
+ * server in determining the resource server to handle the authorization request for
2126
+ */
2127
+ resource?: string;
2128
+ /**
2129
+ * Presentation during issuance sessios if credentials were presented
2130
+ * as part of an issuance session
2131
+ */
2132
+ presentationDuringIssuanceSession?: string;
2133
+ /**
2134
+ * Additional payload to include in the authorization challenge request. Items will be encoded and sent
2135
+ * using x-www-form-urlencoded format. Nested items (JSON) will be stringified and url encoded.
2136
+ */
2137
+ additionalRequestPayload?: Record<string, unknown>;
2138
+ /**
2139
+ * Code verifier to use for pkce. If not provided a value will generated when pkce is supported
2140
+ */
2141
+ pkceCodeVerifier?: string;
2142
+ /**
2143
+ * If client attestation needs to be included in the request.
2144
+ */
2145
+ clientAttestation?: RequestClientAttestationOptions;
2146
+ /**
2147
+ * DPoP options
2148
+ */
2149
+ dpop?: RequestDpopOptions;
2150
+ }
2151
+
2152
+ interface CreateClientAttestationJwtOptions {
2153
+ /**
2154
+ * Creation time of the JWT. If not provided the current date will be used
2155
+ */
2156
+ issuedAt?: Date;
2157
+ /**
2158
+ * Expiration time of the JWT.
2159
+ */
2160
+ expiresAt: Date;
2161
+ /**
2162
+ * Issuer of the client attestation, usually identifier of the client backend
2163
+ */
2164
+ issuer: string;
2165
+ /**
2166
+ * The client id of the client instance.
2167
+ */
2168
+ clientId: string;
2169
+ /**
2170
+ * The confirmation payload for the client, attesting the `jwk`, `key_type` and `user_authentication`
2171
+ */
2172
+ confirmation: ClientAttestationJwtPayload['cnf'];
2173
+ /**
2174
+ * Additional payload to include in the client attestation jwt payload. Will be applied after
2175
+ * any default claims that are included, so add claims with caution.
2176
+ */
2177
+ additionalPayload?: Record<string, unknown>;
2178
+ /**
2179
+ * Callback used for client attestation
2180
+ */
2181
+ callbacks: Pick<CallbackContext, 'signJwt'>;
2182
+ /**
2183
+ * The signer of the client attestation jwt.
2184
+ */
2185
+ signer: JwtSigner;
2186
+ }
2187
+
2188
+ interface Oauth2ClientOptions {
2189
+ /**
2190
+ * Callbacks required for the oauth2 client
2191
+ */
2192
+ callbacks: Omit<CallbackContext, 'verifyJwt' | 'clientAuthentication'>;
2193
+ }
2194
+ declare class Oauth2Client {
2195
+ private options;
2196
+ constructor(options: Oauth2ClientOptions);
2197
+ isDpopSupported(options: {
2198
+ authorizationServerMetadata: AuthorizationServerMetadata;
2199
+ }): {
2200
+ readonly supported: false;
2201
+ readonly dpopSigningAlgValuesSupported?: undefined;
2202
+ } | {
2203
+ readonly supported: true;
2204
+ readonly dpopSigningAlgValuesSupported: string[];
2205
+ };
2206
+ fetchAuthorizationServerMetadata(issuer: string): Promise<({
2207
+ issuer: string;
2208
+ token_endpoint: string;
2209
+ token_endpoint_auth_methods_supported?: string[] | undefined;
2210
+ authorization_endpoint?: string | undefined;
2211
+ jwks_uri?: string | undefined;
2212
+ code_challenge_methods_supported?: string[] | undefined;
2213
+ dpop_signing_alg_values_supported?: string[] | undefined;
2214
+ require_pushed_authorization_requests?: boolean | undefined;
2215
+ pushed_authorization_request_endpoint?: string | undefined;
2216
+ introspection_endpoint?: string | undefined;
2217
+ introspection_endpoint_auth_methods_supported?: string[] | undefined;
2218
+ introspection_endpoint_auth_signing_alg_values_supported?: string[] | undefined;
2219
+ authorization_challenge_endpoint?: string | undefined;
2220
+ 'pre-authorized_grant_anonymous_access_supported'?: boolean | undefined;
2221
+ } & {
2222
+ [key: string]: unknown;
2223
+ }) | null>;
2224
+ /**
2225
+ * Initiate authorization.
2226
+ *
2227
+ * It will take the followings steps:
2228
+ * - if `authorization_challenge_endpoint` is defined, send an authorization challenge request
2229
+ * - if authorization challenge request returns a `redirect_to_web` error code with `request_uri`
2230
+ * then construct the authorization request url based on the `request_uri`
2231
+ * - if the `authorization_challenge_endpoint` is not defined, or authorization challenge request reuturns a `redirect_to_web` error code without `request_uri`
2232
+ * then the authorization request url will be constructed as usual (optionally using PAR).
2233
+ *
2234
+ * @throws {Oauth2ClientAuthorizationChallengeError} in case of an error response. If `error` is
2235
+ * `insufficient_authorization` possible extra steps can be taken.
2236
+ */
2237
+ initiateAuthorization(options: Omit<CreateAuthorizationRequestUrlOptions, 'callbacks'>): Promise<{
2238
+ authorizationRequestUrl: string;
2239
+ pkce: CreatePkceReturn | undefined;
2240
+ dpop: RequestDpopOptions | undefined;
2241
+ } | {
2242
+ dpop: {
2243
+ nonce: any;
2244
+ signer: JwtSignerJwk;
2245
+ } | undefined;
2246
+ authorizationRequestUrl: string;
2247
+ pkce: CreatePkceReturn | undefined;
2248
+ }>;
2249
+ sendAuthorizationChallengeRequest(options: Omit<SendAuthorizationChallengeRequestOptions, 'callbacks'>): Promise<{
2250
+ pkce: CreatePkceReturn | undefined;
2251
+ dpop: {
2252
+ nonce: any;
2253
+ signer: JwtSignerJwk;
2254
+ } | undefined;
2255
+ authorizationChallengeResponse: {
2256
+ authorization_code: string;
2257
+ } & {
2258
+ [key: string]: unknown;
2259
+ };
2260
+ }>;
2261
+ createAuthorizationRequestUrl(options: Omit<CreateAuthorizationRequestUrlOptions, 'callbacks'>): Promise<{
2262
+ authorizationRequestUrl: string;
2263
+ pkce: CreatePkceReturn | undefined;
2264
+ dpop: RequestDpopOptions | undefined;
2265
+ }>;
2266
+ retrievePreAuthorizedCodeAccessToken({ authorizationServerMetadata, preAuthorizedCode, additionalRequestPayload, txCode, dpop, resource, clientAttestation, }: Omit<RetrievePreAuthorizedCodeAccessTokenOptions, 'callbacks'>): Promise<RetrieveAccessTokenReturn>;
2267
+ retrieveAuthorizationCodeAccessToken({ authorizationServerMetadata, additionalRequestPayload, authorizationCode, pkceCodeVerifier, redirectUri, resource, dpop, clientAttestation, }: Omit<RetrieveAuthorizationCodeAccessTokenOptions, 'callbacks'>): Promise<RetrieveAccessTokenReturn>;
2268
+ retrieveRefreshTokenAccessToken({ authorizationServerMetadata, additionalRequestPayload, refreshToken, resource, dpop, clientAttestation, }: Omit<RetrieveRefreshTokenAccessTokenOptions, 'callbacks'>): Promise<RetrieveAccessTokenReturn>;
2269
+ resourceRequest(options: ResourceRequestOptions): Promise<ResourceRequestResponseOk | ResourceRequestResponseNotOk>;
2270
+ /**
2271
+ * @todo move this to another class?
2272
+ */
2273
+ createClientAttestationJwt(options: Omit<CreateClientAttestationJwtOptions, 'callbacks'>): Promise<string>;
2274
+ }
2275
+
2276
+ export { type AccessTokenErrorResponse, type AccessTokenProfileJwtPayload, type AccessTokenResponse, type AuthorizationChallengeErrorResponse, type AuthorizationChallengeRequest, type AuthorizationChallengeResponse, type AuthorizationCodeGrantIdentifier, type AuthorizationServerMetadata, type CalculateJwkThumbprintOptions, type CallbackContext, type ClientAttestationJwtHeader, type ClientAttestationJwtPayload, type ClientAttestationPopJwtHeader, type ClientAttestationPopJwtPayload, type ClientAuthenticationCallback, type ClientAuthenticationCallbackOptions, type ClientAuthenticationClientSecretBasicOptions, type ClientAuthenticationClientSecretPostOptions, type ClientAuthenticationDynamicOptions, type CreateAuthorizationRequestUrlOptions, type CreatePkceReturn, type DecodeJwtOptions, type DecodeJwtResult, type GenerateRandomCallback, HashAlgorithm, type HashCallback, type Jwk, type JwkSet, type JwtSigner, type JwtSignerCustom, type JwtSignerDid, type JwtSignerJwk, type JwtSignerWithJwk, type JwtSignerX5c, Oauth2AuthorizationServer, type Oauth2AuthorizationServerOptions, Oauth2Client, Oauth2ClientAuthorizationChallengeError, Oauth2ClientErrorResponseError, type Oauth2ClientOptions, Oauth2Error, Oauth2ErrorCodes, type Oauth2ErrorOptions, type Oauth2ErrorResponse, Oauth2JwtParseError, Oauth2JwtVerificationError, Oauth2ResourceServer, type Oauth2ResourceServerOptions, Oauth2ResourceUnauthorizedError, Oauth2ServerErrorResponseError, PkceCodeChallengeMethod, type PreAuthorizedCodeGrantIdentifier, type RefreshTokenGrantIdentifier, type RequestClientAttestationOptions, type RequestDpopOptions, type ResourceRequestOptions, type ResourceRequestResponseNotOk, type ResourceRequestResponseOk, type RetrieveAuthorizationCodeAccessTokenOptions, type RetrievePreAuthorizedCodeAccessTokenOptions, type SignJwtCallback, SupportedAuthenticationScheme, type TokenIntrospectionResponse, type VerifyAccessTokenRequestReturn, type VerifyJwtCallback, type VerifyJwtOptions, type VerifyResourceRequestOptions, type WwwAuthenticateHeaderChallenge, authorizationCodeGrantIdentifier, calculateJwkThumbprint, clientAuthenticationClientSecretBasic, clientAuthenticationClientSecretPost, clientAuthenticationDynamic, clientAuthenticationNone, decodeJwt, fetchAuthorizationServerMetadata, fetchJwks, fetchWellKnownMetadata, getAuthorizationServerMetadataFromList, isJwkInSet, jwtHeaderFromJwtSigner, jwtSignerFromJwt, preAuthorizedCodeGrantIdentifier, refreshTokenGrantIdentifier, resourceRequest, vAuthorizationCodeGrantIdentifier, vAuthorizationServerMetadata, vCompactJwt, vJwk, vJwtHeader, vJwtPayload, vOauth2ErrorResponse, vPreAuthorizedCodeGrantIdentifier, vRefreshTokenGrantIdentifier, verifyJwt, verifyResourceRequest };