oauth4webapi 2.13.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +147 -37
- package/build/index.js +59 -8
- package/package.json +5 -5
package/build/index.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
|
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
61
61
|
*
|
|
62
|
-
* CryptoKey
|
|
62
|
+
* {@link !CryptoKey.algorithm} for the `PS256`, `PS384`, or `PS512` JWS Algorithm Identifiers
|
|
63
63
|
*
|
|
64
64
|
* ```ts
|
|
65
65
|
* interface PS256 extends RsaHashedKeyAlgorithm {
|
|
@@ -80,7 +80,7 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
|
|
|
80
80
|
*
|
|
81
81
|
* @example
|
|
82
82
|
*
|
|
83
|
-
* CryptoKey
|
|
83
|
+
* {@link !CryptoKey.algorithm} for the `ES256`, `ES384`, or `ES512` JWS Algorithm Identifiers
|
|
84
84
|
*
|
|
85
85
|
* ```ts
|
|
86
86
|
* interface ES256 extends EcKeyAlgorithm {
|
|
@@ -101,7 +101,7 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
|
|
|
101
101
|
*
|
|
102
102
|
* @example
|
|
103
103
|
*
|
|
104
|
-
* CryptoKey
|
|
104
|
+
* {@link !CryptoKey.algorithm} for the `RS256`, `RS384`, or `RS512` JWS Algorithm Identifiers
|
|
105
105
|
*
|
|
106
106
|
* ```ts
|
|
107
107
|
* interface RS256 extends RsaHashedKeyAlgorithm {
|
|
@@ -122,7 +122,7 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
|
|
|
122
122
|
*
|
|
123
123
|
* @example
|
|
124
124
|
*
|
|
125
|
-
* CryptoKey
|
|
125
|
+
* {@link !CryptoKey.algorithm} for the `EdDSA` JWS Algorithm Identifier (Experimental)
|
|
126
126
|
*
|
|
127
127
|
* Runtime support for this algorithm is limited, it depends on the [Secure Curves in the Web
|
|
128
128
|
* Cryptography API](https://wicg.github.io/webcrypto-secure-curves/) proposal which is yet to be
|
|
@@ -196,29 +196,29 @@ export declare const clockSkew: unique symbol;
|
|
|
196
196
|
export declare const clockTolerance: unique symbol;
|
|
197
197
|
/**
|
|
198
198
|
* When configured on an interface that extends {@link HttpRequestOptions}, this applies to `options`
|
|
199
|
-
* parameter for functions that trigger HTTP requests, this replaces the use of global fetch. As
|
|
200
|
-
* fetch replacement the arguments and expected return are the same as fetch.
|
|
199
|
+
* parameter for functions that may trigger HTTP requests, this replaces the use of global fetch. As
|
|
200
|
+
* a fetch replacement the arguments and expected return are the same as fetch.
|
|
201
201
|
*
|
|
202
202
|
* In theory any module that claims to be compatible with the Fetch API can be used but your mileage
|
|
203
|
-
* may vary. No workarounds to allow use of non-conform {@link Response}s will be considered.
|
|
203
|
+
* may vary. No workarounds to allow use of non-conform {@link !Response}s will be considered.
|
|
204
204
|
*
|
|
205
|
-
* If you only need to update the {@link Request} properties you do not need to use a Fetch API
|
|
205
|
+
* If you only need to update the {@link !Request} properties you do not need to use a Fetch API
|
|
206
206
|
* module, just change what you need and pass it to globalThis.fetch just like this module would
|
|
207
207
|
* normally do.
|
|
208
208
|
*
|
|
209
209
|
* Its intended use cases are:
|
|
210
210
|
*
|
|
211
|
-
* - {@link Request}/{@link Response} tracing and logging
|
|
211
|
+
* - {@link !Request}/{@link !Response} tracing and logging
|
|
212
212
|
* - Custom caching strategies for responses of Authorization Server Metadata and JSON Web Key Set
|
|
213
213
|
* (JWKS) endpoints
|
|
214
|
-
* - Changing the {@link Request} properties like headers, body, credentials, mode before it is passed
|
|
214
|
+
* - Changing the {@link !Request} properties like headers, body, credentials, mode before it is passed
|
|
215
215
|
* to fetch
|
|
216
216
|
*
|
|
217
217
|
* Known caveats:
|
|
218
218
|
*
|
|
219
219
|
* - Expect Type-related issues when passing the inputs through to fetch-like modules, they hardly
|
|
220
220
|
* ever get their typings inline with actual fetch, you should `@ts-expect-error` them.
|
|
221
|
-
* - Returning self-constructed {@link Response} instances prohibits AS/RS-signalled DPoP Nonce
|
|
221
|
+
* - Returning self-constructed {@link !Response} instances prohibits AS/RS-signalled DPoP Nonce
|
|
222
222
|
* caching.
|
|
223
223
|
*
|
|
224
224
|
* @example
|
|
@@ -288,7 +288,7 @@ export declare const customFetch: unique symbol;
|
|
|
288
288
|
* is not desirable.
|
|
289
289
|
*
|
|
290
290
|
* When configured on an interface that extends {@link JWKSCacheOptions}, this applies to `options`
|
|
291
|
-
* parameter for functions that trigger HTTP requests
|
|
291
|
+
* parameter for functions that may trigger HTTP requests to
|
|
292
292
|
* {@link AuthorizationServer.jwks_uri `as.jwks_uri`}, this allows the passed in object to:
|
|
293
293
|
*
|
|
294
294
|
* - Serve as an initial value for the JSON Web Key Set that the module would otherwise need to
|
|
@@ -851,8 +851,8 @@ export interface DiscoveryRequestOptions extends HttpRequestOptions {
|
|
|
851
851
|
*/
|
|
852
852
|
export declare function discoveryRequest(issuerIdentifier: URL, options?: DiscoveryRequestOptions): Promise<Response>;
|
|
853
853
|
/**
|
|
854
|
-
* Validates Response instance to be one coming from the authorization server's well-known
|
|
855
|
-
* endpoint.
|
|
854
|
+
* Validates {@link !Response} instance to be one coming from the authorization server's well-known
|
|
855
|
+
* discovery endpoint.
|
|
856
856
|
*
|
|
857
857
|
* @param expectedIssuerIdentifier Expected Issuer Identifier value.
|
|
858
858
|
* @param response Resolved value from {@link discoveryRequest}.
|
|
@@ -999,6 +999,9 @@ export interface OAuth2Error {
|
|
|
999
999
|
* @group Token Revocation
|
|
1000
1000
|
* @group Refreshing an Access Token
|
|
1001
1001
|
* @group Pushed Authorization Requests (PAR)
|
|
1002
|
+
* @group JWT Bearer Token Grant Type
|
|
1003
|
+
* @group SAML 2.0 Bearer Assertion Grant Type
|
|
1004
|
+
* @group Token Exchange Grant Type
|
|
1002
1005
|
*/
|
|
1003
1006
|
export declare function isOAuth2Error(input?: TokenEndpointResponse | OAuth2TokenEndpointResponse | OpenIDTokenEndpointResponse | ClientCredentialsGrantResponse | DeviceAuthorizationResponse | IntrospectionResponse | OAuth2Error | PushedAuthorizationResponse | URLSearchParams | UserInfoResponse): input is OAuth2Error;
|
|
1004
1007
|
export interface WWWAuthenticateChallengeParameters {
|
|
@@ -1021,7 +1024,7 @@ export interface WWWAuthenticateChallenge {
|
|
|
1021
1024
|
readonly parameters: WWWAuthenticateChallengeParameters;
|
|
1022
1025
|
}
|
|
1023
1026
|
/**
|
|
1024
|
-
* Parses the `WWW-Authenticate` HTTP Header from a Response instance.
|
|
1027
|
+
* Parses the `WWW-Authenticate` HTTP Header from a {@link !Response} instance.
|
|
1025
1028
|
*
|
|
1026
1029
|
* @returns Array of {@link WWWAuthenticateChallenge} objects. Their order from the response is
|
|
1027
1030
|
* preserved. `undefined` when there wasn't a `WWW-Authenticate` HTTP Header returned.
|
|
@@ -1036,10 +1039,13 @@ export interface WWWAuthenticateChallenge {
|
|
|
1036
1039
|
* @group Token Revocation
|
|
1037
1040
|
* @group Refreshing an Access Token
|
|
1038
1041
|
* @group Pushed Authorization Requests (PAR)
|
|
1042
|
+
* @group JWT Bearer Token Grant Type
|
|
1043
|
+
* @group SAML 2.0 Bearer Assertion Grant Type
|
|
1044
|
+
* @group Token Exchange Grant Type
|
|
1039
1045
|
*/
|
|
1040
1046
|
export declare function parseWwwAuthenticateChallenges(response: Response): WWWAuthenticateChallenge[] | undefined;
|
|
1041
1047
|
/**
|
|
1042
|
-
* Validates Response instance to be one coming from the
|
|
1048
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1043
1049
|
* {@link AuthorizationServer.pushed_authorization_request_endpoint `as.pushed_authorization_request_endpoint`}.
|
|
1044
1050
|
*
|
|
1045
1051
|
* @param as Authorization Server Metadata.
|
|
@@ -1144,7 +1150,7 @@ export type JWKSCacheInput = ExportedJWKSCache | Record<string, never>;
|
|
|
1144
1150
|
*/
|
|
1145
1151
|
export declare const skipSubjectCheck: unique symbol;
|
|
1146
1152
|
/**
|
|
1147
|
-
* Validates Response instance to be one coming from the
|
|
1153
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1148
1154
|
* {@link AuthorizationServer.userinfo_endpoint `as.userinfo_endpoint`}.
|
|
1149
1155
|
*
|
|
1150
1156
|
* @param as Authorization Server Metadata.
|
|
@@ -1205,8 +1211,77 @@ export declare function getValidatedIdTokenClaims(ref: OpenIDTokenEndpointRespon
|
|
|
1205
1211
|
* @returns JWT Claims Set from an ID Token, or undefined if there is no ID Token in `ref`.
|
|
1206
1212
|
*/
|
|
1207
1213
|
export declare function getValidatedIdTokenClaims(ref: TokenEndpointResponse): IDToken | undefined;
|
|
1214
|
+
export interface ValidateSignatureOptions extends HttpRequestOptions, JWKSCacheOptions {
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Validates the JWS Signature of an ID Token included in results previously resolved from
|
|
1218
|
+
* {@link processAuthorizationCodeOpenIDResponse}, {@link processRefreshTokenResponse}, or
|
|
1219
|
+
* {@link processDeviceCodeResponse} for non-repudiation purposes.
|
|
1220
|
+
*
|
|
1221
|
+
* Note: Validating signatures of ID Tokens received via direct communication between the Client and
|
|
1222
|
+
* the Token Endpoint (which it is here) is not mandatory since the TLS server validation is used to
|
|
1223
|
+
* validate the issuer instead of checking the token signature. You only need to use this method for
|
|
1224
|
+
* non-repudiation purposes.
|
|
1225
|
+
*
|
|
1226
|
+
* Note: Supports only digital signatures.
|
|
1227
|
+
*
|
|
1228
|
+
* @param as Authorization Server Metadata.
|
|
1229
|
+
* @param ref Value previously resolved from {@link processAuthorizationCodeOpenIDResponse},
|
|
1230
|
+
* {@link processRefreshTokenResponse}, or {@link processDeviceCodeResponse}.
|
|
1231
|
+
*
|
|
1232
|
+
* @returns Resolves if the signature validates, rejects otherwise.
|
|
1233
|
+
*
|
|
1234
|
+
* @group Authorization Code Grant w/ OpenID Connect (OIDC)
|
|
1235
|
+
* @group FAPI 1.0 Advanced
|
|
1236
|
+
*
|
|
1237
|
+
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation)
|
|
1238
|
+
*/
|
|
1239
|
+
export declare function validateIdTokenSignature(as: AuthorizationServer, ref: OpenIDTokenEndpointResponse | TokenEndpointResponse, options?: ValidateSignatureOptions): Promise<void>;
|
|
1240
|
+
/**
|
|
1241
|
+
* Validates the JWS Signature of a JWT {@link !Response} body of response previously processed by
|
|
1242
|
+
* {@link processUserInfoResponse} for non-repudiation purposes.
|
|
1243
|
+
*
|
|
1244
|
+
* Note: Validating signatures of JWTs received via direct communication between the Client and a
|
|
1245
|
+
* TLS-secured Endpoint (which it is here) is not mandatory since the TLS server validation is used
|
|
1246
|
+
* to validate the issuer instead of checking the token signature. You only need to use this method
|
|
1247
|
+
* for non-repudiation purposes.
|
|
1248
|
+
*
|
|
1249
|
+
* Note: Supports only digital signatures.
|
|
1250
|
+
*
|
|
1251
|
+
* @param as Authorization Server Metadata.
|
|
1252
|
+
* @param ref Response previously processed by {@link processUserInfoResponse}.
|
|
1253
|
+
*
|
|
1254
|
+
* @returns Resolves if the signature validates, rejects otherwise.
|
|
1255
|
+
*
|
|
1256
|
+
* @group Authorization Code Grant w/ OpenID Connect (OIDC)
|
|
1257
|
+
* @group OpenID Connect (OIDC) UserInfo
|
|
1258
|
+
*
|
|
1259
|
+
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
|
|
1260
|
+
*/
|
|
1261
|
+
export declare function validateJwtUserInfoSignature(as: AuthorizationServer, ref: Response, options?: ValidateSignatureOptions): Promise<void>;
|
|
1208
1262
|
/**
|
|
1209
|
-
* Validates
|
|
1263
|
+
* Validates the JWS Signature of an JWT {@link !Response} body of responses previously processed by
|
|
1264
|
+
* {@link processIntrospectionResponse} for non-repudiation purposes.
|
|
1265
|
+
*
|
|
1266
|
+
* Note: Validating signatures of JWTs received via direct communication between the Client and a
|
|
1267
|
+
* TLS-secured Endpoint (which it is here) is not mandatory since the TLS server validation is used
|
|
1268
|
+
* to validate the issuer instead of checking the token signature. You only need to use this method
|
|
1269
|
+
* for non-repudiation purposes.
|
|
1270
|
+
*
|
|
1271
|
+
* Note: Supports only digital signatures.
|
|
1272
|
+
*
|
|
1273
|
+
* @param as Authorization Server Metadata.
|
|
1274
|
+
* @param ref Response previously processed by {@link processIntrospectionResponse}.
|
|
1275
|
+
*
|
|
1276
|
+
* @returns Resolves if the signature validates, rejects otherwise.
|
|
1277
|
+
*
|
|
1278
|
+
* @group Token Introspection
|
|
1279
|
+
*
|
|
1280
|
+
* @see [draft-ietf-oauth-jwt-introspection-response-12 - JWT Response for OAuth Token Introspection](https://www.ietf.org/archive/id/draft-ietf-oauth-jwt-introspection-response-12.html#section-5)
|
|
1281
|
+
*/
|
|
1282
|
+
export declare function validateJwtIntrospectionSignature(as: AuthorizationServer, ref: Response, options?: ValidateSignatureOptions): Promise<void>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Validates Refresh Token Grant {@link !Response} instance to be one coming from the
|
|
1210
1285
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1211
1286
|
*
|
|
1212
1287
|
* @param as Authorization Server Metadata.
|
|
@@ -1336,8 +1411,8 @@ export declare const expectNoNonce: unique symbol;
|
|
|
1336
1411
|
*/
|
|
1337
1412
|
export declare const skipAuthTimeCheck: unique symbol;
|
|
1338
1413
|
/**
|
|
1339
|
-
* (OpenID Connect only) Validates Authorization Code Grant Response instance to be one
|
|
1340
|
-
* the {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1414
|
+
* (OpenID Connect only) Validates Authorization Code Grant {@link !Response} instance to be one
|
|
1415
|
+
* coming from the {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1341
1416
|
*
|
|
1342
1417
|
* @param as Authorization Server Metadata.
|
|
1343
1418
|
* @param client Client Metadata.
|
|
@@ -1360,8 +1435,9 @@ export declare const skipAuthTimeCheck: unique symbol;
|
|
|
1360
1435
|
*/
|
|
1361
1436
|
export declare function processAuthorizationCodeOpenIDResponse(as: AuthorizationServer, client: Client, response: Response, expectedNonce?: string | typeof expectNoNonce, maxAge?: number | typeof skipAuthTimeCheck): Promise<OpenIDTokenEndpointResponse | OAuth2Error>;
|
|
1362
1437
|
/**
|
|
1363
|
-
* (OAuth 2.0 without OpenID Connect only) Validates Authorization Code Grant Response
|
|
1364
|
-
* be one coming from the
|
|
1438
|
+
* (OAuth 2.0 without OpenID Connect only) Validates Authorization Code Grant {@link !Response}
|
|
1439
|
+
* instance to be one coming from the
|
|
1440
|
+
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1365
1441
|
*
|
|
1366
1442
|
* @param as Authorization Server Metadata.
|
|
1367
1443
|
* @param client Client Metadata.
|
|
@@ -1392,7 +1468,25 @@ export interface ClientCredentialsGrantRequestOptions extends HttpRequestOptions
|
|
|
1392
1468
|
*/
|
|
1393
1469
|
export declare function clientCredentialsGrantRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: ClientCredentialsGrantRequestOptions): Promise<Response>;
|
|
1394
1470
|
/**
|
|
1395
|
-
*
|
|
1471
|
+
* Performs any Grant request at the {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1472
|
+
* The purpose is to be able to execute grant requests such as Token Exchange Grant Type, JWT Bearer
|
|
1473
|
+
* Token Grant Type, or SAML 2.0 Bearer Assertion Grant Type.
|
|
1474
|
+
*
|
|
1475
|
+
* @param as Authorization Server Metadata.
|
|
1476
|
+
* @param client Client Metadata.
|
|
1477
|
+
* @param grantType Grant Type.
|
|
1478
|
+
*
|
|
1479
|
+
* @group JWT Bearer Token Grant Type
|
|
1480
|
+
* @group SAML 2.0 Bearer Assertion Grant Type
|
|
1481
|
+
* @group Token Exchange Grant Type
|
|
1482
|
+
*
|
|
1483
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc8693.html Token Exchange Grant Type}
|
|
1484
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7523.html#section-2.1 JWT Bearer Token Grant Type}
|
|
1485
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7522.html#section-2.1 SAML 2.0 Bearer Assertion Grant Type}
|
|
1486
|
+
*/
|
|
1487
|
+
export declare function genericTokenEndpointRequest(as: AuthorizationServer, client: Client, grantType: string, parameters: URLSearchParams | Record<string, string> | string[][], options?: Omit<TokenEndpointRequestOptions, 'additionalParameters'>): Promise<Response>;
|
|
1488
|
+
/**
|
|
1489
|
+
* Validates Client Credentials Grant {@link !Response} instance to be one coming from the
|
|
1396
1490
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1397
1491
|
*
|
|
1398
1492
|
* @param as Authorization Server Metadata.
|
|
@@ -1429,7 +1523,7 @@ export interface RevocationRequestOptions extends HttpRequestOptions, Authentica
|
|
|
1429
1523
|
*/
|
|
1430
1524
|
export declare function revocationRequest(as: AuthorizationServer, client: Client, token: string, options?: RevocationRequestOptions): Promise<Response>;
|
|
1431
1525
|
/**
|
|
1432
|
-
* Validates Response instance to be one coming from the
|
|
1526
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1433
1527
|
* {@link AuthorizationServer.revocation_endpoint `as.revocation_endpoint`}.
|
|
1434
1528
|
*
|
|
1435
1529
|
* @param response Resolved value from {@link revocationRequest}.
|
|
@@ -1497,7 +1591,7 @@ export interface IntrospectionResponse {
|
|
|
1497
1591
|
readonly [claim: string]: JsonValue | undefined;
|
|
1498
1592
|
}
|
|
1499
1593
|
/**
|
|
1500
|
-
* Validates Response instance to be one coming from the
|
|
1594
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1501
1595
|
* {@link AuthorizationServer.introspection_endpoint `as.introspection_endpoint`}.
|
|
1502
1596
|
*
|
|
1503
1597
|
* @param as Authorization Server Metadata.
|
|
@@ -1517,8 +1611,6 @@ export declare function processIntrospectionResponse(as: AuthorizationServer, cl
|
|
|
1517
1611
|
export interface JWKS {
|
|
1518
1612
|
readonly keys: JWK[];
|
|
1519
1613
|
}
|
|
1520
|
-
export interface ValidateJwtAuthResponseOptions extends HttpRequestOptions, JWKSCacheOptions {
|
|
1521
|
-
}
|
|
1522
1614
|
/**
|
|
1523
1615
|
* Same as {@link validateAuthResponse} but for signed JARM responses.
|
|
1524
1616
|
*
|
|
@@ -1535,9 +1627,7 @@ export interface ValidateJwtAuthResponseOptions extends HttpRequestOptions, JWKS
|
|
|
1535
1627
|
*
|
|
1536
1628
|
* @see [JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)](https://openid.net/specs/openid-financial-api-jarm.html)
|
|
1537
1629
|
*/
|
|
1538
|
-
export declare function validateJwtAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck, options?:
|
|
1539
|
-
export interface ValidateDetachedSignatureResponseOptions extends HttpRequestOptions, JWKSCacheOptions {
|
|
1540
|
-
}
|
|
1630
|
+
export declare function validateJwtAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck, options?: ValidateSignatureOptions): Promise<URLSearchParams | OAuth2Error>;
|
|
1541
1631
|
/**
|
|
1542
1632
|
* Same as {@link validateAuthResponse} but for FAPI 1.0 Advanced Detached Signature authorization
|
|
1543
1633
|
* responses.
|
|
@@ -1560,7 +1650,7 @@ export interface ValidateDetachedSignatureResponseOptions extends HttpRequestOpt
|
|
|
1560
1650
|
*
|
|
1561
1651
|
* @see [Financial-grade API Security Profile 1.0 - Part 2: Advanced](https://openid.net/specs/openid-financial-api-part-2-1_0.html#id-token-as-detached-signature)
|
|
1562
1652
|
*/
|
|
1563
|
-
export declare function validateDetachedSignatureResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedNonce: string, expectedState?: string | typeof expectNoState, maxAge?: number | typeof skipAuthTimeCheck, options?:
|
|
1653
|
+
export declare function validateDetachedSignatureResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedNonce: string, expectedState?: string | typeof expectNoState, maxAge?: number | typeof skipAuthTimeCheck, options?: ValidateSignatureOptions): Promise<URLSearchParams | OAuth2Error>;
|
|
1564
1654
|
/**
|
|
1565
1655
|
* DANGER ZONE - This option has security implications that must be understood, assessed for
|
|
1566
1656
|
* applicability, and accepted before use.
|
|
@@ -1623,7 +1713,7 @@ export interface DeviceAuthorizationResponse {
|
|
|
1623
1713
|
readonly [parameter: string]: JsonValue | undefined;
|
|
1624
1714
|
}
|
|
1625
1715
|
/**
|
|
1626
|
-
* Validates Response instance to be one coming from the
|
|
1716
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1627
1717
|
* {@link AuthorizationServer.device_authorization_endpoint `as.device_authorization_endpoint`}.
|
|
1628
1718
|
*
|
|
1629
1719
|
* @param as Authorization Server Metadata.
|
|
@@ -1654,7 +1744,7 @@ export declare function processDeviceAuthorizationResponse(as: AuthorizationServ
|
|
|
1654
1744
|
*/
|
|
1655
1745
|
export declare function deviceCodeGrantRequest(as: AuthorizationServer, client: Client, deviceCode: string, options?: TokenEndpointRequestOptions): Promise<Response>;
|
|
1656
1746
|
/**
|
|
1657
|
-
* Validates Device Authorization Grant Response instance to be one coming from the
|
|
1747
|
+
* Validates Device Authorization Grant {@link !Response} instance to be one coming from the
|
|
1658
1748
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1659
1749
|
*
|
|
1660
1750
|
* @param as Authorization Server Metadata.
|
|
@@ -1680,12 +1770,12 @@ export interface GenerateKeyPairOptions {
|
|
|
1680
1770
|
*/
|
|
1681
1771
|
modulusLength?: number;
|
|
1682
1772
|
/**
|
|
1683
|
-
* (EdDSA
|
|
1773
|
+
* (EdDSA algorithm only) The EdDSA sub-type. Default is `Ed25519`.
|
|
1684
1774
|
*/
|
|
1685
1775
|
crv?: 'Ed25519' | 'Ed448';
|
|
1686
1776
|
}
|
|
1687
1777
|
/**
|
|
1688
|
-
* Generates a CryptoKeyPair for a given JWS `alg` Algorithm identifier.
|
|
1778
|
+
* Generates a {@link !CryptoKeyPair} for a given JWS `alg` Algorithm identifier.
|
|
1689
1779
|
*
|
|
1690
1780
|
* @param alg Supported JWS `alg` Algorithm identifier.
|
|
1691
1781
|
*
|
|
@@ -1719,7 +1809,7 @@ export interface ValidateJWTAccessTokenOptions extends HttpRequestOptions, JWKSC
|
|
|
1719
1809
|
[clockTolerance]?: number;
|
|
1720
1810
|
}
|
|
1721
1811
|
/**
|
|
1722
|
-
* Validates use of JSON Web Token (JWT) OAuth 2.0 Access Tokens for a given {@link Request} as per
|
|
1812
|
+
* Validates use of JSON Web Token (JWT) OAuth 2.0 Access Tokens for a given {@link !Request} as per
|
|
1723
1813
|
* RFC 6750, RFC 9068, and RFC 9449.
|
|
1724
1814
|
*
|
|
1725
1815
|
* The only supported means of sending access tokens is via the Authorization Request Header Field
|
|
@@ -1791,17 +1881,37 @@ export type IntrospectionConfirmationClaims = ConfirmationClaims;
|
|
|
1791
1881
|
*
|
|
1792
1882
|
* @deprecated Use {@link validateDetachedSignatureResponse}.
|
|
1793
1883
|
*/
|
|
1794
|
-
export declare const experimental_validateDetachedSignatureResponse: (as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedNonce: string, expectedState?: string | typeof expectNoState | undefined, maxAge?: number | typeof skipAuthTimeCheck | undefined, options?:
|
|
1884
|
+
export declare const experimental_validateDetachedSignatureResponse: (as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedNonce: string, expectedState?: string | typeof expectNoState | undefined, maxAge?: number | typeof skipAuthTimeCheck | undefined, options?: ValidateSignatureOptions | undefined) => ReturnType<typeof validateDetachedSignatureResponse>;
|
|
1795
1885
|
/**
|
|
1796
1886
|
* @ignore
|
|
1797
1887
|
*
|
|
1798
1888
|
* @deprecated Use {@link validateJwtAccessToken}.
|
|
1799
1889
|
*/
|
|
1800
1890
|
export declare const experimental_validateJwtAccessToken: (as: AuthorizationServer, request: Request, expectedAudience: string, options?: ValidateJWTAccessTokenOptions | undefined) => ReturnType<typeof validateJwtAccessToken>;
|
|
1891
|
+
/**
|
|
1892
|
+
* @ignore
|
|
1893
|
+
*
|
|
1894
|
+
* @deprecated Use {@link validateJwtUserinfoSignature}.
|
|
1895
|
+
*/
|
|
1896
|
+
export declare const validateJwtUserinfoSignature: (as: AuthorizationServer, ref: Response, options?: ValidateSignatureOptions | undefined) => ReturnType<typeof validateJwtUserInfoSignature>;
|
|
1801
1897
|
/**
|
|
1802
1898
|
* @ignore
|
|
1803
1899
|
*
|
|
1804
1900
|
* @deprecated Use {@link jwksCache}.
|
|
1805
1901
|
*/
|
|
1806
1902
|
export declare const experimental_jwksCache: symbol;
|
|
1903
|
+
/**
|
|
1904
|
+
* @ignore
|
|
1905
|
+
*
|
|
1906
|
+
* @deprecated Use {@link ValidateSignatureOptions}.
|
|
1907
|
+
*/
|
|
1908
|
+
export interface ValidateJwtResponseSignatureOptions extends ValidateSignatureOptions {
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* @ignore
|
|
1912
|
+
*
|
|
1913
|
+
* @deprecated Use {@link ValidateSignatureOptions}.
|
|
1914
|
+
*/
|
|
1915
|
+
export interface ValidateDetachedSignatureResponseOptions extends ValidateSignatureOptions {
|
|
1916
|
+
}
|
|
1807
1917
|
export {};
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let USER_AGENT;
|
|
2
2
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
3
3
|
const NAME = 'oauth4webapi';
|
|
4
|
-
const VERSION = 'v2.
|
|
4
|
+
const VERSION = 'v2.15.0';
|
|
5
5
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
6
6
|
}
|
|
7
7
|
function looseInstanceOf(input, expected) {
|
|
@@ -858,9 +858,11 @@ export async function processUserInfoResponse(as, client, expectedSubject, respo
|
|
|
858
858
|
let json;
|
|
859
859
|
if (getContentType(response) === 'application/jwt') {
|
|
860
860
|
assertReadableResponse(response);
|
|
861
|
-
const
|
|
861
|
+
const jwt = await response.text();
|
|
862
|
+
const { claims } = await validateJwt(jwt, checkSigningAlgorithm.bind(undefined, client.userinfo_signed_response_alg, as.userinfo_signing_alg_values_supported), noSignatureCheck, getClockSkew(client), getClockTolerance(client))
|
|
862
863
|
.then(validateOptionalAudience.bind(undefined, client.client_id))
|
|
863
864
|
.then(validateOptionalIssuer.bind(undefined, as.issuer));
|
|
865
|
+
jwtResponseBodies.set(response, jwt);
|
|
864
866
|
json = claims;
|
|
865
867
|
}
|
|
866
868
|
else {
|
|
@@ -926,6 +928,7 @@ export async function refreshTokenGrantRequest(as, client, refreshToken, options
|
|
|
926
928
|
return tokenEndpointRequest(as, client, 'refresh_token', parameters, options);
|
|
927
929
|
}
|
|
928
930
|
const idTokenClaims = new WeakMap();
|
|
931
|
+
const jwtResponseBodies = new WeakMap();
|
|
929
932
|
export function getValidatedIdTokenClaims(ref) {
|
|
930
933
|
if (!ref.id_token) {
|
|
931
934
|
return undefined;
|
|
@@ -936,6 +939,40 @@ export function getValidatedIdTokenClaims(ref) {
|
|
|
936
939
|
}
|
|
937
940
|
return claims;
|
|
938
941
|
}
|
|
942
|
+
export async function validateIdTokenSignature(as, ref, options) {
|
|
943
|
+
assertAs(as);
|
|
944
|
+
if (!getValidatedIdTokenClaims(ref)) {
|
|
945
|
+
throw new OPE('"ref" does not contain an ID Token to verify the signature of');
|
|
946
|
+
}
|
|
947
|
+
const { 0: protectedHeader, 1: payload, 2: encodedSignature } = ref.id_token.split('.');
|
|
948
|
+
const header = JSON.parse(buf(b64u(protectedHeader)));
|
|
949
|
+
if (header.alg.startsWith('HS')) {
|
|
950
|
+
throw new UnsupportedOperationError();
|
|
951
|
+
}
|
|
952
|
+
let key;
|
|
953
|
+
key = await getPublicSigKeyFromIssuerJwksUri(as, options, header);
|
|
954
|
+
await validateJwsSignature(protectedHeader, payload, key, b64u(encodedSignature));
|
|
955
|
+
}
|
|
956
|
+
async function validateJwtResponseSignature(as, ref, options) {
|
|
957
|
+
assertAs(as);
|
|
958
|
+
if (!jwtResponseBodies.has(ref)) {
|
|
959
|
+
throw new OPE('"ref" does not contain a processed JWT Response to verify the signature of');
|
|
960
|
+
}
|
|
961
|
+
const { 0: protectedHeader, 1: payload, 2: encodedSignature, } = jwtResponseBodies.get(ref).split('.');
|
|
962
|
+
const header = JSON.parse(buf(b64u(protectedHeader)));
|
|
963
|
+
if (header.alg.startsWith('HS')) {
|
|
964
|
+
throw new UnsupportedOperationError();
|
|
965
|
+
}
|
|
966
|
+
let key;
|
|
967
|
+
key = await getPublicSigKeyFromIssuerJwksUri(as, options, header);
|
|
968
|
+
await validateJwsSignature(protectedHeader, payload, key, b64u(encodedSignature));
|
|
969
|
+
}
|
|
970
|
+
export function validateJwtUserInfoSignature(as, ref, options) {
|
|
971
|
+
return validateJwtResponseSignature(as, ref, options);
|
|
972
|
+
}
|
|
973
|
+
export function validateJwtIntrospectionSignature(as, ref, options) {
|
|
974
|
+
return validateJwtResponseSignature(as, ref, options);
|
|
975
|
+
}
|
|
939
976
|
async function processGenericAccessTokenResponse(as, client, response, ignoreIdToken = false, ignoreRefreshToken = false) {
|
|
940
977
|
assertAs(as);
|
|
941
978
|
assertClient(client);
|
|
@@ -1161,6 +1198,14 @@ export async function clientCredentialsGrantRequest(as, client, parameters, opti
|
|
|
1161
1198
|
assertClient(client);
|
|
1162
1199
|
return tokenEndpointRequest(as, client, 'client_credentials', new URLSearchParams(parameters), options);
|
|
1163
1200
|
}
|
|
1201
|
+
export async function genericTokenEndpointRequest(as, client, grantType, parameters, options) {
|
|
1202
|
+
assertAs(as);
|
|
1203
|
+
assertClient(client);
|
|
1204
|
+
if (!validateString(grantType)) {
|
|
1205
|
+
throw new TypeError('"grantType" must be a non-empty string');
|
|
1206
|
+
}
|
|
1207
|
+
return tokenEndpointRequest(as, client, grantType, new URLSearchParams(parameters), options);
|
|
1208
|
+
}
|
|
1164
1209
|
export async function processClientCredentialsResponse(as, client, response) {
|
|
1165
1210
|
const result = await processGenericAccessTokenResponse(as, client, response, true, true);
|
|
1166
1211
|
if (isOAuth2Error(result)) {
|
|
@@ -1233,11 +1278,13 @@ export async function processIntrospectionResponse(as, client, response) {
|
|
|
1233
1278
|
let json;
|
|
1234
1279
|
if (getContentType(response) === 'application/token-introspection+jwt') {
|
|
1235
1280
|
assertReadableResponse(response);
|
|
1236
|
-
const
|
|
1281
|
+
const jwt = await response.text();
|
|
1282
|
+
const { claims } = await validateJwt(jwt, checkSigningAlgorithm.bind(undefined, client.introspection_signed_response_alg, as.introspection_signing_alg_values_supported), noSignatureCheck, getClockSkew(client), getClockTolerance(client))
|
|
1237
1283
|
.then(checkJwtType.bind(undefined, 'token-introspection+jwt'))
|
|
1238
1284
|
.then(validatePresence.bind(undefined, ['aud', 'iat', 'iss']))
|
|
1239
1285
|
.then(validateIssuer.bind(undefined, as.issuer))
|
|
1240
1286
|
.then(validateAudience.bind(undefined, client.client_id));
|
|
1287
|
+
jwtResponseBodies.set(response, jwt);
|
|
1241
1288
|
json = claims.token_introspection;
|
|
1242
1289
|
if (!isJsonObject(json)) {
|
|
1243
1290
|
throw new OPE('JWT "token_introspection" claim must be a JSON object');
|
|
@@ -1378,6 +1425,13 @@ function keyToSubtle(key) {
|
|
|
1378
1425
|
throw new UnsupportedOperationError();
|
|
1379
1426
|
}
|
|
1380
1427
|
const noSignatureCheck = Symbol();
|
|
1428
|
+
async function validateJwsSignature(protectedHeader, payload, key, signature) {
|
|
1429
|
+
const input = `${protectedHeader}.${payload}`;
|
|
1430
|
+
const verified = await crypto.subtle.verify(keyToSubtle(key), key, signature, buf(input));
|
|
1431
|
+
if (!verified) {
|
|
1432
|
+
throw new OPE('JWT signature verification failed');
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1381
1435
|
async function validateJwt(jws, checkAlg, getKey, clockSkew, clockTolerance) {
|
|
1382
1436
|
const { 0: protectedHeader, 1: payload, 2: encodedSignature, length } = jws.split('.');
|
|
1383
1437
|
if (length === 5) {
|
|
@@ -1404,11 +1458,7 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew, clockTolerance) {
|
|
|
1404
1458
|
let key;
|
|
1405
1459
|
if (getKey !== noSignatureCheck) {
|
|
1406
1460
|
key = await getKey(header);
|
|
1407
|
-
|
|
1408
|
-
const verified = await crypto.subtle.verify(keyToSubtle(key), key, signature, buf(input));
|
|
1409
|
-
if (!verified) {
|
|
1410
|
-
throw new OPE('JWT signature verification failed');
|
|
1411
|
-
}
|
|
1461
|
+
await validateJwsSignature(protectedHeader, payload, key, signature);
|
|
1412
1462
|
}
|
|
1413
1463
|
let claims;
|
|
1414
1464
|
try {
|
|
@@ -1969,4 +2019,5 @@ export const experimentalUseMtlsAlias = useMtlsAlias;
|
|
|
1969
2019
|
export const experimental_useMtlsAlias = useMtlsAlias;
|
|
1970
2020
|
export const experimental_validateDetachedSignatureResponse = (...args) => validateDetachedSignatureResponse(...args);
|
|
1971
2021
|
export const experimental_validateJwtAccessToken = (...args) => validateJwtAccessToken(...args);
|
|
2022
|
+
export const validateJwtUserinfoSignature = (...args) => validateJwtUserInfoSignature(...args);
|
|
1972
2023
|
export const experimental_jwksCache = jwksCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oauth4webapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "OAuth 2 / OpenID Connect for JavaScript Runtimes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"access token",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"scripts": {
|
|
52
52
|
"_format": "find src test tap examples conformance -type f -name '*.ts' -o -name '*.mjs' -o -name '*.cjs' | xargs prettier",
|
|
53
|
-
"build": "rm -rf build && tsc && tsc --declaration true --emitDeclarationOnly true --removeComments false && tsc -p test && tsc -p examples && tsc -p conformance && tsc -p tap && npx jsr publish --dry-run --allow-dirty",
|
|
53
|
+
"build": "rm -rf build && tsc && tsc --declaration true --emitDeclarationOnly true --removeComments false && tsc -p test && tsc -p examples && tsc -p conformance && tsc -p tap && npx --yes jsr publish --dry-run --allow-dirty",
|
|
54
54
|
"conformance": "bash -c 'source .node_flags.sh && ava --config conformance/ava.config.ts'",
|
|
55
55
|
"docs": "patch-package && typedoc",
|
|
56
56
|
"format": "npm run _format -- --write",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"chrome-launcher": "^1.1.2",
|
|
75
75
|
"edge-runtime": "^3.0.3",
|
|
76
76
|
"esbuild": "^0.23.1",
|
|
77
|
-
"jose": "^5.
|
|
77
|
+
"jose": "^5.9.2",
|
|
78
78
|
"oidc-provider": "^8.5.1",
|
|
79
79
|
"patch-package": "^8.0.0",
|
|
80
80
|
"prettier": "^3.3.3",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"raw-body": "^3.0.0",
|
|
85
85
|
"selfsigned": "^2.4.1",
|
|
86
86
|
"timekeeper": "^2.3.1",
|
|
87
|
-
"tsx": "^4.19.
|
|
88
|
-
"typedoc": "^0.26.
|
|
87
|
+
"tsx": "^4.19.1",
|
|
88
|
+
"typedoc": "^0.26.7",
|
|
89
89
|
"typedoc-plugin-markdown": "^4.2.7",
|
|
90
90
|
"typedoc-plugin-mdn-links": "^3.2.12",
|
|
91
91
|
"typescript": "~5.5.4",
|