oauth4webapi 2.0.2 → 2.0.3

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 CHANGED
@@ -39,7 +39,7 @@ import * as oauth2 from 'oauth4webapi'
39
39
  **`example`** Deno import
40
40
 
41
41
  ```js
42
- import * as oauth2 from 'https://deno.land/x/oauth4webapi@v2.0.2/mod.ts'
42
+ import * as oauth2 from 'https://deno.land/x/oauth4webapi@v2.0.3/mod.ts'
43
43
  ```
44
44
 
45
45
  - Authorization Code Flow - OpenID Connect [source](examples/code.ts), or plain OAuth 2 [source](examples/oauth.ts)
package/build/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- type JsonObject = {
1
+ declare type JsonObject = {
2
2
  [Key in string]?: JsonValue;
3
3
  };
4
- type JsonArray = JsonValue[];
5
- type JsonPrimitive = string | number | boolean | null;
6
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
4
+ declare type JsonArray = JsonValue[];
5
+ declare type JsonPrimitive = string | number | boolean | null;
6
+ declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
7
7
  /**
8
8
  * Interface to pass an asymmetric private key and, optionally, its associated JWK Key ID to be
9
9
  * added as a `kid` JOSE Header Parameter.
@@ -41,7 +41,7 @@ export interface PrivateKey {
41
41
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication)
42
42
  * @see [OAuth Token Endpoint Authentication Methods](https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#token-endpoint-auth-method)
43
43
  */
44
- export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_post' | 'private_key_jwt' | 'none';
44
+ export declare type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_post' | 'private_key_jwt' | 'none';
45
45
  /**
46
46
  * Supported JWS `alg` Algorithm identifiers.
47
47
  *
@@ -84,7 +84,7 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
84
84
  * }
85
85
  * ```
86
86
  */
87
- export type JWSAlgorithm = 'PS256' | 'ES256' | 'RS256' | 'EdDSA';
87
+ export declare type JWSAlgorithm = 'PS256' | 'ES256' | 'RS256' | 'EdDSA';
88
88
  /**
89
89
  * Authorization Server Metadata
90
90
  *
@@ -1014,7 +1014,7 @@ declare class CallbackParameters extends URLSearchParams {
1014
1014
  * @see [RFC 9207 - OAuth 2.0 Authorization Server Issuer Identification](https://www.rfc-editor.org/rfc/rfc9207.html)
1015
1015
  */
1016
1016
  export declare function validateAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck): CallbackParameters | OAuth2Error;
1017
- type ReturnTypes = TokenEndpointResponse | OAuth2TokenEndpointResponse | OpenIDTokenEndpointResponse | ClientCredentialsGrantResponse | DeviceAuthorizationResponse | IntrospectionResponse | OAuth2Error | PushedAuthorizationResponse | URLSearchParams | UserInfoResponse;
1017
+ declare type ReturnTypes = TokenEndpointResponse | OAuth2TokenEndpointResponse | OpenIDTokenEndpointResponse | ClientCredentialsGrantResponse | DeviceAuthorizationResponse | IntrospectionResponse | OAuth2Error | PushedAuthorizationResponse | URLSearchParams | UserInfoResponse;
1018
1018
  export interface DeviceAuthorizationRequestOptions extends HttpRequestOptions, AuthenticatedRequestOptions {
1019
1019
  }
1020
1020
  /**
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.0.1';
4
+ const VERSION = 'v2.0.3';
5
5
  USER_AGENT = `${NAME}/${VERSION}`;
6
6
  }
7
7
  const encoder = new TextEncoder();
@@ -114,10 +114,6 @@ function isPublicKey(key) {
114
114
  return isCryptoKey(key) && key.type === 'public';
115
115
  }
116
116
  const SUPPORTED_JWS_ALGS = ['PS256', 'ES256', 'RS256', 'EdDSA'];
117
- function preserveBodyStream(response) {
118
- assertReadableResponse(response);
119
- return response.clone();
120
- }
121
117
  function processDpopNonce(response) {
122
118
  const url = new URL(response.url);
123
119
  if (response.headers.has('dpop-nonce')) {
@@ -205,9 +201,10 @@ export async function processDiscoveryResponse(expectedIssuerIdentifier, respons
205
201
  if (response.status !== 200) {
206
202
  throw new OPE('"response" is not a conform Authorization Server Metadata response');
207
203
  }
204
+ assertReadableResponse(response);
208
205
  let json;
209
206
  try {
210
- json = await preserveBodyStream(response).json();
207
+ json = await response.json();
211
208
  }
212
209
  catch {
213
210
  throw new OPE('failed to parse "response" body as JSON');
@@ -590,9 +587,10 @@ export async function processPushedAuthorizationResponse(as, client, response) {
590
587
  }
591
588
  throw new OPE('"response" is not a conform Pushed Authorization Request Endpoint response');
592
589
  }
590
+ assertReadableResponse(response);
593
591
  let json;
594
592
  try {
595
- json = await preserveBodyStream(response).json();
593
+ json = await response.json();
596
594
  }
597
595
  catch {
598
596
  throw new OPE('failed to parse "response" body as JSON');
@@ -743,7 +741,8 @@ export async function processUserInfoResponse(as, client, expectedSubject, respo
743
741
  }
744
742
  let json;
745
743
  if (getContentType(response) === 'application/jwt') {
746
- const { claims } = await validateJwt(await preserveBodyStream(response).text(), checkSigningAlgorithm.bind(undefined, client.userinfo_signed_response_alg, as.userinfo_signing_alg_values_supported), noSignatureCheck)
744
+ assertReadableResponse(response);
745
+ const { claims } = await validateJwt(await response.text(), checkSigningAlgorithm.bind(undefined, client.userinfo_signed_response_alg, as.userinfo_signing_alg_values_supported), noSignatureCheck)
747
746
  .then(validateOptionalAudience.bind(undefined, client.client_id))
748
747
  .then(validateOptionalIssuer.bind(undefined, as.issuer));
749
748
  json = claims;
@@ -752,8 +751,9 @@ export async function processUserInfoResponse(as, client, expectedSubject, respo
752
751
  if (client.userinfo_signed_response_alg) {
753
752
  throw new OPE('JWT UserInfo Response expected');
754
753
  }
754
+ assertReadableResponse(response);
755
755
  try {
756
- json = await preserveBodyStream(response).json();
756
+ json = await response.json();
757
757
  }
758
758
  catch {
759
759
  throw new OPE('failed to parse "response" body as JSON');
@@ -832,9 +832,10 @@ async function processGenericAccessTokenResponse(as, client, response, ignoreIdT
832
832
  }
833
833
  throw new OPE('"response" is not a conform Token Endpoint response');
834
834
  }
835
+ assertReadableResponse(response);
835
836
  let json;
836
837
  try {
837
- json = await preserveBodyStream(response).json();
838
+ json = await response.json();
838
839
  }
839
840
  catch {
840
841
  throw new OPE('failed to parse "response" body as JSON');
@@ -1100,7 +1101,8 @@ export async function processIntrospectionResponse(as, client, response) {
1100
1101
  }
1101
1102
  let json;
1102
1103
  if (getContentType(response) === 'application/token-introspection+jwt') {
1103
- const { claims } = await validateJwt(await preserveBodyStream(response).text(), checkSigningAlgorithm.bind(undefined, client.introspection_signed_response_alg, as.introspection_signing_alg_values_supported), noSignatureCheck)
1104
+ assertReadableResponse(response);
1105
+ const { claims } = await validateJwt(await response.text(), checkSigningAlgorithm.bind(undefined, client.introspection_signed_response_alg, as.introspection_signing_alg_values_supported), noSignatureCheck)
1104
1106
  .then(checkJwtType.bind(undefined, 'token-introspection+jwt'))
1105
1107
  .then(validatePresence.bind(undefined, ['aud', 'iat', 'iss']))
1106
1108
  .then(validateIssuer.bind(undefined, as.issuer))
@@ -1111,8 +1113,9 @@ export async function processIntrospectionResponse(as, client, response) {
1111
1113
  }
1112
1114
  }
1113
1115
  else {
1116
+ assertReadableResponse(response);
1114
1117
  try {
1115
- json = await preserveBodyStream(response).json();
1118
+ json = await response.json();
1116
1119
  }
1117
1120
  catch {
1118
1121
  throw new OPE('failed to parse "response" body as JSON');
@@ -1149,9 +1152,10 @@ async function processJwksResponse(response) {
1149
1152
  if (response.status !== 200) {
1150
1153
  throw new OPE('"response" is not a conform JSON Web Key Set response');
1151
1154
  }
1155
+ assertReadableResponse(response);
1152
1156
  let json;
1153
1157
  try {
1154
- json = await preserveBodyStream(response).json();
1158
+ json = await response.json();
1155
1159
  }
1156
1160
  catch {
1157
1161
  throw new OPE('failed to parse "response" body as JSON');
@@ -1169,8 +1173,9 @@ async function processJwksResponse(response) {
1169
1173
  }
1170
1174
  async function handleOAuthBodyError(response) {
1171
1175
  if (response.status > 399 && response.status < 500) {
1176
+ assertReadableResponse(response);
1172
1177
  try {
1173
- const json = await preserveBodyStream(response).json();
1178
+ const json = await response.json();
1174
1179
  if (isJsonObject(json) && typeof json.error === 'string' && json.error.length) {
1175
1180
  if (json.error_description !== undefined && typeof json.error_description !== 'string') {
1176
1181
  delete json.error_description;
@@ -1458,9 +1463,10 @@ export async function processDeviceAuthorizationResponse(as, client, response) {
1458
1463
  }
1459
1464
  throw new OPE('"response" is not a conform Device Authorization Endpoint response');
1460
1465
  }
1466
+ assertReadableResponse(response);
1461
1467
  let json;
1462
1468
  try {
1463
- json = await preserveBodyStream(response).json();
1469
+ json = await response.json();
1464
1470
  }
1465
1471
  catch {
1466
1472
  throw new OPE('failed to parse "response" body as JSON');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth4webapi",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "OAuth 2 / OpenID Connect for Web Platform API JavaScript runtimes",
5
5
  "keywords": [
6
6
  "auth",