oauth4webapi 2.12.2 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/build/index.d.ts +118 -38
- package/build/index.js +50 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Support from the community to continue maintaining and improving this module is
|
|
|
33
33
|
|
|
34
34
|
## [API Reference](docs/README.md)
|
|
35
35
|
|
|
36
|
-
`oauth4webapi` is distributed via [npmjs.com](https://www.npmjs.com/package/oauth4webapi), [deno.land/x](https://deno.land/x/oauth4webapi), [cdnjs.com](https://cdnjs.com/libraries/oauth4webapi), [jsdelivr.com](https://www.jsdelivr.com/package/npm/oauth4webapi), and [github.com](https://github.com/panva/oauth4webapi).
|
|
36
|
+
`oauth4webapi` is distributed via [npmjs.com](https://www.npmjs.com/package/oauth4webapi), [jsr.io](https://jsr.io/@panva/oauth4webapi), [deno.land/x](https://deno.land/x/oauth4webapi), [cdnjs.com](https://cdnjs.com/libraries/oauth4webapi), [jsdelivr.com](https://www.jsdelivr.com/package/npm/oauth4webapi), and [github.com](https://github.com/panva/oauth4webapi).
|
|
37
37
|
|
|
38
38
|
## [Examples](examples/README.md)
|
|
39
39
|
|
|
@@ -43,12 +43,6 @@ Support from the community to continue maintaining and improving this module is
|
|
|
43
43
|
import * as oauth from 'oauth4webapi'
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
**`example`** Deno import
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
import * as oauth from 'https://deno.land/x/oauth4webapi@v2.12.2/mod.ts'
|
|
50
|
-
```
|
|
51
|
-
|
|
52
46
|
- Authorization Code Flow (OAuth 2.0) - [source](examples/oauth.ts)
|
|
53
47
|
- Authorization Code Flow (OpenID Connect) - [source](examples/oidc.ts) | [diff](examples/oidc.diff)
|
|
54
48
|
- Extensions
|
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}.
|
|
@@ -1021,7 +1021,7 @@ export interface WWWAuthenticateChallenge {
|
|
|
1021
1021
|
readonly parameters: WWWAuthenticateChallengeParameters;
|
|
1022
1022
|
}
|
|
1023
1023
|
/**
|
|
1024
|
-
* Parses the `WWW-Authenticate` HTTP Header from a Response instance.
|
|
1024
|
+
* Parses the `WWW-Authenticate` HTTP Header from a {@link !Response} instance.
|
|
1025
1025
|
*
|
|
1026
1026
|
* @returns Array of {@link WWWAuthenticateChallenge} objects. Their order from the response is
|
|
1027
1027
|
* preserved. `undefined` when there wasn't a `WWW-Authenticate` HTTP Header returned.
|
|
@@ -1039,7 +1039,7 @@ export interface WWWAuthenticateChallenge {
|
|
|
1039
1039
|
*/
|
|
1040
1040
|
export declare function parseWwwAuthenticateChallenges(response: Response): WWWAuthenticateChallenge[] | undefined;
|
|
1041
1041
|
/**
|
|
1042
|
-
* Validates Response instance to be one coming from the
|
|
1042
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1043
1043
|
* {@link AuthorizationServer.pushed_authorization_request_endpoint `as.pushed_authorization_request_endpoint`}.
|
|
1044
1044
|
*
|
|
1045
1045
|
* @param as Authorization Server Metadata.
|
|
@@ -1144,7 +1144,7 @@ export type JWKSCacheInput = ExportedJWKSCache | Record<string, never>;
|
|
|
1144
1144
|
*/
|
|
1145
1145
|
export declare const skipSubjectCheck: unique symbol;
|
|
1146
1146
|
/**
|
|
1147
|
-
* Validates Response instance to be one coming from the
|
|
1147
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1148
1148
|
* {@link AuthorizationServer.userinfo_endpoint `as.userinfo_endpoint`}.
|
|
1149
1149
|
*
|
|
1150
1150
|
* @param as Authorization Server Metadata.
|
|
@@ -1205,8 +1205,77 @@ export declare function getValidatedIdTokenClaims(ref: OpenIDTokenEndpointRespon
|
|
|
1205
1205
|
* @returns JWT Claims Set from an ID Token, or undefined if there is no ID Token in `ref`.
|
|
1206
1206
|
*/
|
|
1207
1207
|
export declare function getValidatedIdTokenClaims(ref: TokenEndpointResponse): IDToken | undefined;
|
|
1208
|
+
export interface ValidateSignatureOptions extends HttpRequestOptions, JWKSCacheOptions {
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Validates the JWS Signature of an ID Token included in results previously resolved from
|
|
1212
|
+
* {@link processAuthorizationCodeOpenIDResponse}, {@link processRefreshTokenResponse}, or
|
|
1213
|
+
* {@link processDeviceCodeResponse} for non-repudiation purposes.
|
|
1214
|
+
*
|
|
1215
|
+
* Note: Validating signatures of ID Tokens received via direct communication between the Client and
|
|
1216
|
+
* the Token Endpoint (which it is here) is not mandatory since the TLS server validation is used to
|
|
1217
|
+
* validate the issuer instead of checking the token signature. You only need to use this method for
|
|
1218
|
+
* non-repudiation purposes.
|
|
1219
|
+
*
|
|
1220
|
+
* Note: Supports only digital signatures.
|
|
1221
|
+
*
|
|
1222
|
+
* @param as Authorization Server Metadata.
|
|
1223
|
+
* @param ref Value previously resolved from {@link processAuthorizationCodeOpenIDResponse},
|
|
1224
|
+
* {@link processRefreshTokenResponse}, or {@link processDeviceCodeResponse}.
|
|
1225
|
+
*
|
|
1226
|
+
* @returns Resolves if the signature validates, rejects otherwise.
|
|
1227
|
+
*
|
|
1228
|
+
* @group Authorization Code Grant w/ OpenID Connect (OIDC)
|
|
1229
|
+
* @group FAPI 1.0 Advanced
|
|
1230
|
+
*
|
|
1231
|
+
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation)
|
|
1232
|
+
*/
|
|
1233
|
+
export declare function validateIdTokenSignature(as: AuthorizationServer, ref: OpenIDTokenEndpointResponse | TokenEndpointResponse, options?: ValidateSignatureOptions): Promise<void>;
|
|
1234
|
+
/**
|
|
1235
|
+
* Validates the JWS Signature of a JWT {@link !Response} body of response previously processed by
|
|
1236
|
+
* {@link processUserInfoResponse} for non-repudiation purposes.
|
|
1237
|
+
*
|
|
1238
|
+
* Note: Validating signatures of JWTs received via direct communication between the Client and a
|
|
1239
|
+
* TLS-secured Endpoint (which it is here) is not mandatory since the TLS server validation is used
|
|
1240
|
+
* to validate the issuer instead of checking the token signature. You only need to use this method
|
|
1241
|
+
* for non-repudiation purposes.
|
|
1242
|
+
*
|
|
1243
|
+
* Note: Supports only digital signatures.
|
|
1244
|
+
*
|
|
1245
|
+
* @param as Authorization Server Metadata.
|
|
1246
|
+
* @param ref Response previously processed by {@link processUserInfoResponse}.
|
|
1247
|
+
*
|
|
1248
|
+
* @returns Resolves if the signature validates, rejects otherwise.
|
|
1249
|
+
*
|
|
1250
|
+
* @group Authorization Code Grant w/ OpenID Connect (OIDC)
|
|
1251
|
+
* @group OpenID Connect (OIDC) UserInfo
|
|
1252
|
+
*
|
|
1253
|
+
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
|
|
1254
|
+
*/
|
|
1255
|
+
export declare function validateJwtUserinfoSignature(as: AuthorizationServer, ref: Response, options?: ValidateSignatureOptions): Promise<void>;
|
|
1208
1256
|
/**
|
|
1209
|
-
* Validates
|
|
1257
|
+
* Validates the JWS Signature of an JWT {@link !Response} body of responses previously processed by
|
|
1258
|
+
* {@link processIntrospectionResponse} for non-repudiation purposes.
|
|
1259
|
+
*
|
|
1260
|
+
* Note: Validating signatures of JWTs received via direct communication between the Client and a
|
|
1261
|
+
* TLS-secured Endpoint (which it is here) is not mandatory since the TLS server validation is used
|
|
1262
|
+
* to validate the issuer instead of checking the token signature. You only need to use this method
|
|
1263
|
+
* for non-repudiation purposes.
|
|
1264
|
+
*
|
|
1265
|
+
* Note: Supports only digital signatures.
|
|
1266
|
+
*
|
|
1267
|
+
* @param as Authorization Server Metadata.
|
|
1268
|
+
* @param ref Response previously processed by {@link processIntrospectionResponse}.
|
|
1269
|
+
*
|
|
1270
|
+
* @returns Resolves if the signature validates, rejects otherwise.
|
|
1271
|
+
*
|
|
1272
|
+
* @group Token Introspection
|
|
1273
|
+
*
|
|
1274
|
+
* @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)
|
|
1275
|
+
*/
|
|
1276
|
+
export declare function validateJwtIntrospectionSignature(as: AuthorizationServer, ref: Response, options?: ValidateSignatureOptions): Promise<void>;
|
|
1277
|
+
/**
|
|
1278
|
+
* Validates Refresh Token Grant {@link !Response} instance to be one coming from the
|
|
1210
1279
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1211
1280
|
*
|
|
1212
1281
|
* @param as Authorization Server Metadata.
|
|
@@ -1336,8 +1405,8 @@ export declare const expectNoNonce: unique symbol;
|
|
|
1336
1405
|
*/
|
|
1337
1406
|
export declare const skipAuthTimeCheck: unique symbol;
|
|
1338
1407
|
/**
|
|
1339
|
-
* (OpenID Connect only) Validates Authorization Code Grant Response instance to be one
|
|
1340
|
-
* the {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1408
|
+
* (OpenID Connect only) Validates Authorization Code Grant {@link !Response} instance to be one
|
|
1409
|
+
* coming from the {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1341
1410
|
*
|
|
1342
1411
|
* @param as Authorization Server Metadata.
|
|
1343
1412
|
* @param client Client Metadata.
|
|
@@ -1360,8 +1429,9 @@ export declare const skipAuthTimeCheck: unique symbol;
|
|
|
1360
1429
|
*/
|
|
1361
1430
|
export declare function processAuthorizationCodeOpenIDResponse(as: AuthorizationServer, client: Client, response: Response, expectedNonce?: string | typeof expectNoNonce, maxAge?: number | typeof skipAuthTimeCheck): Promise<OpenIDTokenEndpointResponse | OAuth2Error>;
|
|
1362
1431
|
/**
|
|
1363
|
-
* (OAuth 2.0 without OpenID Connect only) Validates Authorization Code Grant Response
|
|
1364
|
-
* be one coming from the
|
|
1432
|
+
* (OAuth 2.0 without OpenID Connect only) Validates Authorization Code Grant {@link !Response}
|
|
1433
|
+
* instance to be one coming from the
|
|
1434
|
+
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1365
1435
|
*
|
|
1366
1436
|
* @param as Authorization Server Metadata.
|
|
1367
1437
|
* @param client Client Metadata.
|
|
@@ -1392,7 +1462,7 @@ export interface ClientCredentialsGrantRequestOptions extends HttpRequestOptions
|
|
|
1392
1462
|
*/
|
|
1393
1463
|
export declare function clientCredentialsGrantRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: ClientCredentialsGrantRequestOptions): Promise<Response>;
|
|
1394
1464
|
/**
|
|
1395
|
-
* Validates Client Credentials Grant Response instance to be one coming from the
|
|
1465
|
+
* Validates Client Credentials Grant {@link !Response} instance to be one coming from the
|
|
1396
1466
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1397
1467
|
*
|
|
1398
1468
|
* @param as Authorization Server Metadata.
|
|
@@ -1429,7 +1499,7 @@ export interface RevocationRequestOptions extends HttpRequestOptions, Authentica
|
|
|
1429
1499
|
*/
|
|
1430
1500
|
export declare function revocationRequest(as: AuthorizationServer, client: Client, token: string, options?: RevocationRequestOptions): Promise<Response>;
|
|
1431
1501
|
/**
|
|
1432
|
-
* Validates Response instance to be one coming from the
|
|
1502
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1433
1503
|
* {@link AuthorizationServer.revocation_endpoint `as.revocation_endpoint`}.
|
|
1434
1504
|
*
|
|
1435
1505
|
* @param response Resolved value from {@link revocationRequest}.
|
|
@@ -1497,7 +1567,7 @@ export interface IntrospectionResponse {
|
|
|
1497
1567
|
readonly [claim: string]: JsonValue | undefined;
|
|
1498
1568
|
}
|
|
1499
1569
|
/**
|
|
1500
|
-
* Validates Response instance to be one coming from the
|
|
1570
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1501
1571
|
* {@link AuthorizationServer.introspection_endpoint `as.introspection_endpoint`}.
|
|
1502
1572
|
*
|
|
1503
1573
|
* @param as Authorization Server Metadata.
|
|
@@ -1517,8 +1587,6 @@ export declare function processIntrospectionResponse(as: AuthorizationServer, cl
|
|
|
1517
1587
|
export interface JWKS {
|
|
1518
1588
|
readonly keys: JWK[];
|
|
1519
1589
|
}
|
|
1520
|
-
export interface ValidateJwtAuthResponseOptions extends HttpRequestOptions, JWKSCacheOptions {
|
|
1521
|
-
}
|
|
1522
1590
|
/**
|
|
1523
1591
|
* Same as {@link validateAuthResponse} but for signed JARM responses.
|
|
1524
1592
|
*
|
|
@@ -1535,9 +1603,7 @@ export interface ValidateJwtAuthResponseOptions extends HttpRequestOptions, JWKS
|
|
|
1535
1603
|
*
|
|
1536
1604
|
* @see [JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)](https://openid.net/specs/openid-financial-api-jarm.html)
|
|
1537
1605
|
*/
|
|
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
|
-
}
|
|
1606
|
+
export declare function validateJwtAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck, options?: ValidateSignatureOptions): Promise<URLSearchParams | OAuth2Error>;
|
|
1541
1607
|
/**
|
|
1542
1608
|
* Same as {@link validateAuthResponse} but for FAPI 1.0 Advanced Detached Signature authorization
|
|
1543
1609
|
* responses.
|
|
@@ -1560,7 +1626,7 @@ export interface ValidateDetachedSignatureResponseOptions extends HttpRequestOpt
|
|
|
1560
1626
|
*
|
|
1561
1627
|
* @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
1628
|
*/
|
|
1563
|
-
export declare function validateDetachedSignatureResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedNonce: string, expectedState?: string | typeof expectNoState, maxAge?: number | typeof skipAuthTimeCheck, options?:
|
|
1629
|
+
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
1630
|
/**
|
|
1565
1631
|
* DANGER ZONE - This option has security implications that must be understood, assessed for
|
|
1566
1632
|
* applicability, and accepted before use.
|
|
@@ -1623,7 +1689,7 @@ export interface DeviceAuthorizationResponse {
|
|
|
1623
1689
|
readonly [parameter: string]: JsonValue | undefined;
|
|
1624
1690
|
}
|
|
1625
1691
|
/**
|
|
1626
|
-
* Validates Response instance to be one coming from the
|
|
1692
|
+
* Validates {@link !Response} instance to be one coming from the
|
|
1627
1693
|
* {@link AuthorizationServer.device_authorization_endpoint `as.device_authorization_endpoint`}.
|
|
1628
1694
|
*
|
|
1629
1695
|
* @param as Authorization Server Metadata.
|
|
@@ -1654,7 +1720,7 @@ export declare function processDeviceAuthorizationResponse(as: AuthorizationServ
|
|
|
1654
1720
|
*/
|
|
1655
1721
|
export declare function deviceCodeGrantRequest(as: AuthorizationServer, client: Client, deviceCode: string, options?: TokenEndpointRequestOptions): Promise<Response>;
|
|
1656
1722
|
/**
|
|
1657
|
-
* Validates Device Authorization Grant Response instance to be one coming from the
|
|
1723
|
+
* Validates Device Authorization Grant {@link !Response} instance to be one coming from the
|
|
1658
1724
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
1659
1725
|
*
|
|
1660
1726
|
* @param as Authorization Server Metadata.
|
|
@@ -1680,12 +1746,12 @@ export interface GenerateKeyPairOptions {
|
|
|
1680
1746
|
*/
|
|
1681
1747
|
modulusLength?: number;
|
|
1682
1748
|
/**
|
|
1683
|
-
* (EdDSA
|
|
1749
|
+
* (EdDSA algorithm only) The EdDSA sub-type. Default is `Ed25519`.
|
|
1684
1750
|
*/
|
|
1685
1751
|
crv?: 'Ed25519' | 'Ed448';
|
|
1686
1752
|
}
|
|
1687
1753
|
/**
|
|
1688
|
-
* Generates a CryptoKeyPair for a given JWS `alg` Algorithm identifier.
|
|
1754
|
+
* Generates a {@link !CryptoKeyPair} for a given JWS `alg` Algorithm identifier.
|
|
1689
1755
|
*
|
|
1690
1756
|
* @param alg Supported JWS `alg` Algorithm identifier.
|
|
1691
1757
|
*
|
|
@@ -1719,7 +1785,7 @@ export interface ValidateJWTAccessTokenOptions extends HttpRequestOptions, JWKSC
|
|
|
1719
1785
|
[clockTolerance]?: number;
|
|
1720
1786
|
}
|
|
1721
1787
|
/**
|
|
1722
|
-
* Validates use of JSON Web Token (JWT) OAuth 2.0 Access Tokens for a given {@link Request} as per
|
|
1788
|
+
* Validates use of JSON Web Token (JWT) OAuth 2.0 Access Tokens for a given {@link !Request} as per
|
|
1723
1789
|
* RFC 6750, RFC 9068, and RFC 9449.
|
|
1724
1790
|
*
|
|
1725
1791
|
* The only supported means of sending access tokens is via the Authorization Request Header Field
|
|
@@ -1791,17 +1857,31 @@ export type IntrospectionConfirmationClaims = ConfirmationClaims;
|
|
|
1791
1857
|
*
|
|
1792
1858
|
* @deprecated Use {@link validateDetachedSignatureResponse}.
|
|
1793
1859
|
*/
|
|
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?:
|
|
1860
|
+
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
1861
|
/**
|
|
1796
1862
|
* @ignore
|
|
1797
1863
|
*
|
|
1798
1864
|
* @deprecated Use {@link validateJwtAccessToken}.
|
|
1799
1865
|
*/
|
|
1800
|
-
export declare const experimental_validateJwtAccessToken: (as: AuthorizationServer, request: Request, expectedAudience: string, options?: ValidateJWTAccessTokenOptions | undefined) =>
|
|
1866
|
+
export declare const experimental_validateJwtAccessToken: (as: AuthorizationServer, request: Request, expectedAudience: string, options?: ValidateJWTAccessTokenOptions | undefined) => ReturnType<typeof validateJwtAccessToken>;
|
|
1801
1867
|
/**
|
|
1802
1868
|
* @ignore
|
|
1803
1869
|
*
|
|
1804
1870
|
* @deprecated Use {@link jwksCache}.
|
|
1805
1871
|
*/
|
|
1806
1872
|
export declare const experimental_jwksCache: symbol;
|
|
1873
|
+
/**
|
|
1874
|
+
* @ignore
|
|
1875
|
+
*
|
|
1876
|
+
* @deprecated Use {@link ValidateSignatureOptions}.
|
|
1877
|
+
*/
|
|
1878
|
+
export interface ValidateJwtResponseSignatureOptions extends ValidateSignatureOptions {
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* @ignore
|
|
1882
|
+
*
|
|
1883
|
+
* @deprecated Use {@link ValidateSignatureOptions}.
|
|
1884
|
+
*/
|
|
1885
|
+
export interface ValidateDetachedSignatureResponseOptions extends ValidateSignatureOptions {
|
|
1886
|
+
}
|
|
1807
1887
|
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.14.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);
|
|
@@ -1233,11 +1270,13 @@ export async function processIntrospectionResponse(as, client, response) {
|
|
|
1233
1270
|
let json;
|
|
1234
1271
|
if (getContentType(response) === 'application/token-introspection+jwt') {
|
|
1235
1272
|
assertReadableResponse(response);
|
|
1236
|
-
const
|
|
1273
|
+
const jwt = await response.text();
|
|
1274
|
+
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
1275
|
.then(checkJwtType.bind(undefined, 'token-introspection+jwt'))
|
|
1238
1276
|
.then(validatePresence.bind(undefined, ['aud', 'iat', 'iss']))
|
|
1239
1277
|
.then(validateIssuer.bind(undefined, as.issuer))
|
|
1240
1278
|
.then(validateAudience.bind(undefined, client.client_id));
|
|
1279
|
+
jwtResponseBodies.set(response, jwt);
|
|
1241
1280
|
json = claims.token_introspection;
|
|
1242
1281
|
if (!isJsonObject(json)) {
|
|
1243
1282
|
throw new OPE('JWT "token_introspection" claim must be a JSON object');
|
|
@@ -1378,6 +1417,13 @@ function keyToSubtle(key) {
|
|
|
1378
1417
|
throw new UnsupportedOperationError();
|
|
1379
1418
|
}
|
|
1380
1419
|
const noSignatureCheck = Symbol();
|
|
1420
|
+
async function validateJwsSignature(protectedHeader, payload, key, signature) {
|
|
1421
|
+
const input = `${protectedHeader}.${payload}`;
|
|
1422
|
+
const verified = await crypto.subtle.verify(keyToSubtle(key), key, signature, buf(input));
|
|
1423
|
+
if (!verified) {
|
|
1424
|
+
throw new OPE('JWT signature verification failed');
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1381
1427
|
async function validateJwt(jws, checkAlg, getKey, clockSkew, clockTolerance) {
|
|
1382
1428
|
const { 0: protectedHeader, 1: payload, 2: encodedSignature, length } = jws.split('.');
|
|
1383
1429
|
if (length === 5) {
|
|
@@ -1404,11 +1450,7 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew, clockTolerance) {
|
|
|
1404
1450
|
let key;
|
|
1405
1451
|
if (getKey !== noSignatureCheck) {
|
|
1406
1452
|
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
|
-
}
|
|
1453
|
+
await validateJwsSignature(protectedHeader, payload, key, signature);
|
|
1412
1454
|
}
|
|
1413
1455
|
let claims;
|
|
1414
1456
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oauth4webapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.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",
|
|
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",
|