@monocloud/auth-core 0.1.3 → 0.1.5

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
@@ -1,10 +1,26 @@
1
- ![MonoCloud Logo](https://raw.githubusercontent.com/monocloud/auth-js/refs/heads/main/MonoCloud.png)
1
+ <div align="center">
2
+ <a href="https://www.monocloud.com?utm_source=github&utm_medium=auth_js" target="_blank" rel="noopener noreferrer">
3
+ <picture>
4
+ <img src="https://raw.githubusercontent.com/monocloud/auth-js/refs/heads/main/packages/core/banner.svg" alt="MonoCloud Banner">
5
+ </picture>
6
+ </a>
7
+ <div align="right">
8
+ <a href="https://www.npmjs.com/package/@monocloud/auth-core" target="_blank">
9
+ <img src="https://img.shields.io/npm/v/@monocloud/auth-core" alt="NPM" />
10
+ </a>
11
+ <a href="https://opensource.org/licenses/MIT">
12
+ <img src="https://img.shields.io/:license-MIT-blue.svg?style=flat" alt="License: MIT" />
13
+ </a>
14
+ <a href="https://github.com/monocloud/auth-js/actions/workflows/build.yml">
15
+ <img src="https://github.com/monocloud/auth-js/actions/workflows/build.yml/badge.svg" alt="Build Status" />
16
+ </a>
17
+ </div>
18
+ </div>
2
19
 
3
20
  ## Introduction
4
21
 
5
22
  **MonoCloud OIDC Client for JavaScript — a standards-compliant OpenID Connect client for secure authentication flows.**
6
23
 
7
-
8
24
  [MonoCloud](https://www.monocloud.com?utm_source=github&utm_medium=auth_js) is a modern, developer-friendly Identity & Access Management platform.
9
25
 
10
26
  This package provides a **framework-agnostic OpenID Connect (OIDC) client** for interacting with MonoCloud. It supports industry-standard authentication flows including **Authorization Code Flow**, **PKCE**, **Pushed Authorization Requests (PAR)**, and token lifecycle management.
@@ -79,7 +95,7 @@ const session = await oidcClient.authenticate(
79
95
  'openid profile email'
80
96
  );
81
97
 
82
- console.log(session.user); // User profile claims
98
+ console.log(session.user); // User profile claims
83
99
  console.log(session.idToken); // Raw ID Token
84
100
  ```
85
101
 
package/dist/index.cjs CHANGED
@@ -1,10 +1,25 @@
1
- const require_internal = require('./internal-DytuO03E.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_utils_internal = require('./utils/internal.cjs');
2
3
 
3
4
  //#region src/errors/monocloud-auth-base-error.ts
5
+ /**
6
+ * Base class for all MonoCloud authentication errors.
7
+ *
8
+ * All errors thrown by the MonoCloud SDK extend this class, allowing applications to safely detect and handle MonoCloud-specific failures using `instanceof`.
9
+ *
10
+ * @category Error Classes
11
+ */
4
12
  var MonoCloudAuthBaseError = class extends Error {};
5
13
 
6
14
  //#endregion
7
15
  //#region src/errors/monocloud-op-error.ts
16
+ /**
17
+ * OAuth error returned by the authorization server during an authentication or token request.
18
+ *
19
+ * These errors correspond to standard OAuth / OpenID Connect error responses such as `invalid_request`, `access_denied`, or `invalid_grant`.
20
+ *
21
+ * @category Error Classes
22
+ */
8
23
  var MonoCloudOPError = class extends MonoCloudAuthBaseError {
9
24
  constructor(error, errorDescription) {
10
25
  super(error);
@@ -15,14 +30,31 @@ var MonoCloudOPError = class extends MonoCloudAuthBaseError {
15
30
 
16
31
  //#endregion
17
32
  //#region src/errors/monocloud-http-error.ts
33
+ /**
34
+ * Error thrown when a request to the MonoCloud authorization server fails.
35
+ *
36
+ * This error typically indicates a network failure, an unexpected HTTP response, or an unsuccessful response returned by the authorization server.
37
+ *
38
+ * @category Error Classes
39
+ */
18
40
  var MonoCloudHttpError = class extends MonoCloudAuthBaseError {};
19
41
 
20
42
  //#endregion
21
43
  //#region src/errors/monocloud-token-error.ts
44
+ /**
45
+ * Error thrown when a token operation fails.
46
+ *
47
+ * @category Error Classes
48
+ */
22
49
  var MonoCloudTokenError = class extends MonoCloudAuthBaseError {};
23
50
 
24
51
  //#endregion
25
52
  //#region src/errors/monocloud-validation-error.ts
53
+ /**
54
+ * Error thrown when validation fails.
55
+ *
56
+ * @category Error Classes
57
+ */
26
58
  var MonoCloudValidationError = class extends MonoCloudAuthBaseError {};
27
59
 
28
60
  //#endregion
@@ -140,13 +172,13 @@ const keyToSubtle = (key) => {
140
172
  throw new Error("unsupported CryptoKey algorithm name");
141
173
  };
142
174
  const clientAssertionPayload = (issuer, clientId, skew) => {
143
- const now$1 = Math.floor(Date.now() / 1e3) + skew;
175
+ const now = Math.floor(Date.now() / 1e3) + skew;
144
176
  return {
145
- jti: require_internal.randomBytes(),
177
+ jti: require_utils_internal.randomBytes(),
146
178
  aud: issuer,
147
- exp: now$1 + 60,
148
- iat: now$1,
149
- nbf: now$1,
179
+ exp: now + 60,
180
+ iat: now,
181
+ nbf: now,
150
182
  iss: clientId,
151
183
  sub: clientId
152
184
  };
@@ -160,8 +192,8 @@ const jwtAssertionGenerator = async (issuer, clientId, clientSecret, body, skew)
160
192
  const payload = clientAssertionPayload(issuer, clientId, skew);
161
193
  body.set("client_id", clientId);
162
194
  body.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
163
- const input = `${require_internal.encodeBase64Url(require_internal.stringToArrayBuffer(JSON.stringify(header)))}.${require_internal.encodeBase64Url(require_internal.stringToArrayBuffer(JSON.stringify(payload)))}`;
164
- const signature = require_internal.encodeBase64Url(await crypto.subtle.sign(keyToSubtle(key), key, require_internal.stringToArrayBuffer(input)));
195
+ const input = `${require_utils_internal.encodeBase64Url(require_utils_internal.stringToArrayBuffer(JSON.stringify(header)))}.${require_utils_internal.encodeBase64Url(require_utils_internal.stringToArrayBuffer(JSON.stringify(payload)))}`;
196
+ const signature = require_utils_internal.encodeBase64Url(await crypto.subtle.sign(keyToSubtle(key), key, require_utils_internal.stringToArrayBuffer(input)));
165
197
  body.set("client_assertion", `${input}.${signature}`);
166
198
  };
167
199
  const clientAuth = async (clientId, clientSecret, method, issuer, headers, body, jwtAssertionSkew) => {
@@ -175,7 +207,7 @@ const clientAuth = async (clientId, clientSecret, method, issuer, headers, body,
175
207
  break;
176
208
  case method === "client_secret_jwt" && !!issuer && !!body && (typeof clientSecret === "string" || clientSecret?.kty === "oct"):
177
209
  await jwtAssertionGenerator(issuer, clientId, typeof clientSecret === "string" ? {
178
- k: require_internal.encodeBase64Url(require_internal.stringToArrayBuffer(clientSecret)),
210
+ k: require_utils_internal.encodeBase64Url(require_utils_internal.stringToArrayBuffer(clientSecret)),
179
211
  kty: "oct",
180
212
  alg: "HS256"
181
213
  } : clientSecret, body, jwtAssertionSkew ?? 0);
@@ -223,12 +255,15 @@ const deserializeJson = async (res) => {
223
255
  );
224
256
  }
225
257
  };
258
+ /**
259
+ * @category Classes
260
+ */
226
261
  var MonoCloudOidcClient = class MonoCloudOidcClient {
227
262
  constructor(tenantDomain, clientId, options) {
228
263
  this.jwksCacheExpiry = 0;
229
- this.jwksCacheDuration = 60;
264
+ this.jwksCacheDuration = 300;
230
265
  this.metadataCacheExpiry = 0;
231
- this.metadataCacheDuration = 60;
266
+ this.metadataCacheDuration = 300;
232
267
  tenantDomain ??= "";
233
268
  /* v8 ignore next -- @preserve */
234
269
  this.tenantDomain = `${!tenantDomain.startsWith("https://") ? "https://" : ""}${tenantDomain.endsWith("/") ? tenantDomain.slice(0, -1) : tenantDomain}`;
@@ -244,9 +279,9 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
244
279
  *
245
280
  * If no values are provided for `responseType`, or `codeChallengeMethod`, they default to `code`, and `S256`, respectively.
246
281
  *
247
- * @param params Authorization URL parameters
282
+ * @param params - Authorization URL parameters.
248
283
  *
249
- * @returns Tenant's authorization url.
284
+ * @returns Tenant's authorization URL.
250
285
  *
251
286
  * @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
252
287
  * unexpected status code during the request or a serialization error while processing the response.
@@ -257,7 +292,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
257
292
  queryParams.set("client_id", this.clientId);
258
293
  if (params.redirectUri) queryParams.set("redirect_uri", params.redirectUri);
259
294
  if (params.requestUri) queryParams.set("request_uri", params.requestUri);
260
- const scopes = require_internal.parseSpaceSeparated(params.scopes) ?? [];
295
+ const scopes = require_utils_internal.parseSpaceSeparated(params.scopes) ?? [];
261
296
  if (scopes.length > 0) queryParams.set("scope", scopes.join(" "));
262
297
  if (params.responseType && params.responseType.length > 0) queryParams.set("response_type", params.responseType);
263
298
  if ((!params.responseType || params.responseType.length === 0) && !params.requestUri) queryParams.set("response_type", "code");
@@ -271,7 +306,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
271
306
  if (params.display) queryParams.set("display", params.display);
272
307
  if (typeof params.maxAge === "number") queryParams.set("max_age", params.maxAge.toString());
273
308
  if (params.prompt) queryParams.set("prompt", params.prompt);
274
- const resource = require_internal.parseSpaceSeparated(params.resource) ?? [];
309
+ const resource = require_utils_internal.parseSpaceSeparated(params.resource) ?? [];
275
310
  if (resource.length > 0) for (const r of resource) queryParams.append("resource", r);
276
311
  if (params.codeChallenge) {
277
312
  queryParams.set("code_challenge", params.codeChallenge);
@@ -295,17 +330,17 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
295
330
  *
296
331
  */
297
332
  async getMetadata(forceRefresh = false) {
298
- if (!forceRefresh && this.metadata && this.metadataCacheExpiry > require_internal.now()) return this.metadata;
333
+ if (!forceRefresh && this.metadata && this.metadataCacheExpiry > require_utils_internal.now()) return this.metadata;
299
334
  this.metadata = void 0;
300
335
  const response = await innerFetch(`${this.tenantDomain}/.well-known/openid-configuration`);
301
336
  if (response.status !== 200) throw new MonoCloudHttpError(`Error while fetching metadata. Unexpected status code: ${response.status}`);
302
337
  const metadata = await deserializeJson(response);
303
338
  this.metadata = metadata;
304
- this.metadataCacheExpiry = require_internal.now() + this.metadataCacheDuration;
339
+ this.metadataCacheExpiry = require_utils_internal.now() + this.metadataCacheDuration;
305
340
  return metadata;
306
341
  }
307
342
  /**
308
- * Fetches the JSON Web Keys used to sign the id token.
343
+ * Fetches the JSON Web Keys used to sign the ID token.
309
344
  * The JWKS is cached for 1 minute.
310
345
  *
311
346
  * @param forceRefresh - If `true`, bypasses the cache and fetches fresh set of JWKS from the server.
@@ -317,7 +352,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
317
352
  *
318
353
  */
319
354
  async getJwks(forceRefresh = false) {
320
- if (!forceRefresh && this.jwks && this.jwksCacheExpiry > require_internal.now()) return this.jwks;
355
+ if (!forceRefresh && this.jwks && this.jwksCacheExpiry > require_utils_internal.now()) return this.jwks;
321
356
  this.jwks = void 0;
322
357
  const metadata = await this.getMetadata();
323
358
  assertMetadataProperty(metadata, "jwks_uri");
@@ -325,15 +360,15 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
325
360
  if (response.status !== 200) throw new MonoCloudHttpError(`Error while fetching JWKS. Unexpected status code: ${response.status}`);
326
361
  const jwks = await deserializeJson(response);
327
362
  this.jwks = jwks;
328
- this.jwksCacheExpiry = require_internal.now() + this.jwksCacheDuration;
363
+ this.jwksCacheExpiry = require_utils_internal.now() + this.jwksCacheDuration;
329
364
  return jwks;
330
365
  }
331
366
  /**
332
367
  * Performs a pushed authorization request.
333
368
  *
334
- * @param params - Authorization Parameters
369
+ * @param params - Authorization Parameters.
335
370
  *
336
- * @returns Response from Pushed Authorization Request (PAR) endpoint
371
+ * @returns Response from Pushed Authorization Request (PAR) endpoint.
337
372
  *
338
373
  * @throws {@link MonoCloudOPError} - When the request is invalid.
339
374
  *
@@ -345,7 +380,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
345
380
  const body = new URLSearchParams();
346
381
  body.set("client_id", this.clientId);
347
382
  if (params.redirectUri) body.set("redirect_uri", params.redirectUri);
348
- const scopes = require_internal.parseSpaceSeparated(params.scopes) ?? [];
383
+ const scopes = require_utils_internal.parseSpaceSeparated(params.scopes) ?? [];
349
384
  if (scopes.length > 0) body.set("scope", scopes.join(" "));
350
385
  if (params.responseType && params.responseType.length > 0) body.set("response_type", params.responseType);
351
386
  else body.set("response_type", "code");
@@ -359,7 +394,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
359
394
  if (params.display) body.set("display", params.display);
360
395
  if (typeof params.maxAge === "number") body.set("max_age", params.maxAge.toString());
361
396
  if (params.prompt) body.set("prompt", params.prompt);
362
- const resource = require_internal.parseSpaceSeparated(params.resource) ?? [];
397
+ const resource = require_utils_internal.parseSpaceSeparated(params.resource) ?? [];
363
398
  if (resource.length > 0) for (const r of resource) body.append("resource", r);
364
399
  if (params.codeChallenge) {
365
400
  body.set("code_challenge", params.codeChallenge);
@@ -423,13 +458,13 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
423
458
  return await deserializeJson(response);
424
459
  }
425
460
  /**
426
- * Generates OpenID end session url for signing out.
461
+ * Generates OpenID end session URL for signing out.
427
462
  *
428
463
  * Note - The `state` is added only when `postLogoutRedirectUri` is present.
429
464
  *
430
- * @param params - Parameters to build end session url
465
+ * @param params - Parameters to build end session URL.
431
466
  *
432
- * @returns Tenant's end session url
467
+ * @returns Tenant's end session URL.
433
468
  *
434
469
  * @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
435
470
  * unexpected status code during the request or a serialization error while processing the response.
@@ -453,7 +488,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
453
488
  * @param code - The authorization code received from the authorization server.
454
489
  * @param redirectUri - The redirect URI used in the initial authorization request.
455
490
  * @param codeVerifier - Code verifier for PKCE.
456
- * @param resource - Space-separated list of resources the access token should be scoped to
491
+ * @param resource - Space-separated list of resources the access token should be scoped to.
457
492
  *
458
493
  * @returns Tokens obtained by exchanging an authorization code at the token endpoint.
459
494
  *
@@ -470,7 +505,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
470
505
  body.set("code", code);
471
506
  body.set("redirect_uri", redirectUri);
472
507
  if (codeVerifier) body.set("code_verifier", codeVerifier);
473
- const resources = require_internal.parseSpaceSeparated(resource) ?? [];
508
+ const resources = require_utils_internal.parseSpaceSeparated(resource) ?? [];
474
509
  if (resources.length > 0) for (const r of resources) body.append("resource", r);
475
510
  const headers = {
476
511
  "content-type": "application/x-www-form-urlencoded",
@@ -510,9 +545,9 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
510
545
  const body = new URLSearchParams();
511
546
  body.set("grant_type", "refresh_token");
512
547
  body.set("refresh_token", refreshToken);
513
- const scopes = require_internal.parseSpaceSeparated(options?.scopes) ?? [];
548
+ const scopes = require_utils_internal.parseSpaceSeparated(options?.scopes) ?? [];
514
549
  if (scopes.length > 0) body.set("scope", scopes.join(" "));
515
- const resource = require_internal.parseSpaceSeparated(options?.resource) ?? [];
550
+ const resource = require_utils_internal.parseSpaceSeparated(options?.resource) ?? [];
516
551
  if (resource.length > 0) for (const r of resource) body.append("resource", r);
517
552
  const headers = {
518
553
  "content-type": "application/x-www-form-urlencoded",
@@ -536,23 +571,23 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
536
571
  /**
537
572
  * Generates a session with user and tokens by exchanging authorization code from callback params.
538
573
  *
539
- * @param code - The authorization code received from the callback
540
- * @param redirectUri - The redirect URI that was used in the authorization request
574
+ * @param code - The authorization code received from the callback.
575
+ * @param redirectUri - The redirect URI that was used in the authorization request.
541
576
  * @param requestedScopes - A space-separated list of scopes originally requested via the `/authorize` endpoint.
542
577
  * This is stored in the session to ensure the correct access token can be identified and refreshed during `refreshSession()`.
543
578
  * @param resource - A space-separated list of resource indicators originally requested via the `/authorize` endpoint.
544
579
  * Used alongside scopes to uniquely identify and refresh the specific access token associated with these resources.
545
- * @param options - Options for authenticating a user with authorization code
580
+ * @param options - Options for authenticating a user with authorization code.
546
581
  *
547
582
  * @returns The user's session containing authentication tokens and user information.
548
583
  *
549
584
  * @throws {@link MonoCloudValidationError} - When the token scope does not contain the openid scope,
550
585
  * or if 'expires_in' or 'scope' is missing from the token response.
551
586
  *
552
- * @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized
587
+ * @throws {@link MonoCloudOPError} - When the OpenID Provider returns a standardized.
553
588
  * OAuth 2.0 error response.
554
589
  *
555
- * @throws {@link MonoCloudTokenError} - If ID Token validation fails
590
+ * @throws {@link MonoCloudTokenError} - If ID Token validation fails.
556
591
  *
557
592
  * @throws {@link MonoCloudHttpError} - Thrown if there is a network error during the request or
558
593
  * unexpected status code during the request or a serialization error while processing the response.
@@ -560,7 +595,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
560
595
  */
561
596
  async authenticate(code, redirectUri, requestedScopes, resource, options) {
562
597
  const tokens = await this.exchangeAuthorizationCode(code, redirectUri, options?.codeVerifier, resource);
563
- const accessTokenExpiration = typeof tokens.expires_in === "number" ? require_internal.now() + tokens.expires_in : void 0;
598
+ const accessTokenExpiration = typeof tokens.expires_in === "number" ? require_utils_internal.now() + tokens.expires_in : void 0;
564
599
  if (!accessTokenExpiration) throw new MonoCloudValidationError("Missing required 'expires_in' field");
565
600
  if (!tokens.scope) throw new MonoCloudValidationError("Missing or invalid 'scope' field");
566
601
  let userinfo;
@@ -596,11 +631,11 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
596
631
  * Refetches user information for an existing session using the userinfo endpoint.
597
632
  * Updates the session's user object with the latest user information while preserving existing properties.
598
633
  *
599
- * @param accessToken - Access token used to fetch the userinfo
600
- * @param session - The current MonoCloudSession
601
- * @param options - Userinfo refetch options
634
+ * @param accessToken - Access token used to fetch the userinfo.
635
+ * @param session - The current MonoCloudSession.
636
+ * @param options - Userinfo refetch options.
602
637
  *
603
- * @returns Updated session with the latest userinfo
638
+ * @returns Updated session with the latest userinfo.
604
639
  *
605
640
  * @throws {@link MonoCloudValidationError} - When the token scope does not contain openid scope
606
641
  *
@@ -627,8 +662,8 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
627
662
  * Refreshes an existing session using the refresh token.
628
663
  * This function requests new tokens using the refresh token and optionally updates user information.
629
664
  *
630
- * @param session - The current MonoCloudSession containing the refresh token
631
- * @param options - Session refresh options
665
+ * @param session - The current MonoCloudSession containing the refresh token.
666
+ * @param options - Session refresh options.
632
667
  *
633
668
  * @returns User's session containing refreshed authentication tokens and user information.
634
669
  *
@@ -647,7 +682,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
647
682
  async refreshSession(session, options) {
648
683
  if (!session.refreshToken) throw new MonoCloudValidationError("Session does not contain refresh token");
649
684
  const tokens = await this.refreshGrant(session.refreshToken, options?.refreshGrantOptions);
650
- const accessTokenExpiration = typeof tokens.expires_in === "number" ? require_internal.now() + tokens.expires_in : void 0;
685
+ const accessTokenExpiration = typeof tokens.expires_in === "number" ? require_utils_internal.now() + tokens.expires_in : void 0;
651
686
  if (!accessTokenExpiration) throw new MonoCloudValidationError("Missing required 'expires_in' field");
652
687
  if (!tokens.scope) throw new MonoCloudValidationError("Missing or invalid 'scope' field");
653
688
  let userinfo;
@@ -663,7 +698,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
663
698
  const resource = options?.refreshGrantOptions?.resource;
664
699
  let scopes = options?.refreshGrantOptions?.scopes;
665
700
  if (!resource && !scopes) scopes = session.authorizedScopes;
666
- const accessToken = require_internal.findToken(session.accessTokens, resource, scopes);
701
+ const accessToken = require_utils_internal.findToken(session.accessTokens, resource, scopes);
667
702
  const user = Object.keys(idTokenClaims).length === 0 && !userinfo ? session.user : {
668
703
  ...session.user,
669
704
  ...idTokenClaims,
@@ -690,10 +725,10 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
690
725
  /**
691
726
  * Revokes an access token or refresh token, rendering it invalid for future use.
692
727
  *
693
- * @param token - The token string to be revoked
694
- * @param tokenType - Hint about the token type ('access_token' or 'refresh_token')
728
+ * @param token - The token string to be revoked.
729
+ * @param tokenType - Hint about the token type ('access_token' or 'refresh_token').
695
730
  *
696
- * @returns If token revocation succeeded
731
+ * @returns If token revocation succeeded.
697
732
  *
698
733
  * @throws {@link MonoCloudValidationError} - If token is invalid or unsupported token type
699
734
  *
@@ -727,14 +762,14 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
727
762
  /**
728
763
  * Validates an ID Token.
729
764
  *
730
- * @param idToken - The ID Token JWT string to validate
731
- * @param jwks - Array of JSON Web Keys (JWK) used to verify the token's signature
732
- * @param clockSkew - Number of seconds to adjust the current time to account for clock differences
733
- * @param clockTolerance - Additional time tolerance in seconds for time-based claim validation
734
- * @param maxAge - maximum authentication age in seconds
735
- * @param nonce - nonce value to validate against the token's nonce claim
765
+ * @param idToken - The ID Token JWT string to validate.
766
+ * @param jwks - Array of JSON Web Keys (JWK) used to verify the token's signature.
767
+ * @param clockSkew - Number of seconds to adjust the current time to account for clock differences.
768
+ * @param clockTolerance - Additional time tolerance in seconds for time-based claim validation.
769
+ * @param maxAge - Maximum authentication age in seconds.
770
+ * @param nonce - Nonce value to validate against the token's nonce claim.
736
771
  *
737
- * @returns Validated ID Token claims
772
+ * @returns Validated ID Token claims.
738
773
  *
739
774
  * @throws {@link MonoCloudTokenError} - If ID Token validation fails
740
775
  *
@@ -745,28 +780,28 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
745
780
  if (length !== 3) throw new MonoCloudTokenError("ID Token must have a header, payload and signature");
746
781
  let header;
747
782
  try {
748
- header = JSON.parse(require_internal.decodeBase64Url(protectedHeader));
783
+ header = JSON.parse(require_utils_internal.decodeBase64Url(protectedHeader));
749
784
  } catch {
750
785
  throw new MonoCloudTokenError("Failed to parse JWT Header");
751
786
  }
752
787
  if (header === null || typeof header !== "object" || Array.isArray(header)) throw new MonoCloudTokenError("JWT Header must be a top level object");
753
788
  if (this.idTokenSigningAlgorithm !== header.alg) throw new MonoCloudTokenError("Invalid signing alg");
754
789
  if (header.crit !== void 0) throw new MonoCloudTokenError("Unexpected JWT \"crit\" header parameter");
755
- const binary = require_internal.decodeBase64Url(encodedSignature);
790
+ const binary = require_utils_internal.decodeBase64Url(encodedSignature);
756
791
  const signature = new Uint8Array(binary.length);
757
792
  for (let i = 0; i < binary.length; i++) signature[i] = binary.charCodeAt(i);
758
- const key = await require_internal.getPublicSigKeyFromIssuerJwks(jwks, header);
793
+ const key = await require_utils_internal.getPublicSigKeyFromIssuerJwks(jwks, header);
759
794
  const input = `${protectedHeader}.${payload}`;
760
- if (!await crypto.subtle.verify(keyToSubtle(key), key, signature, require_internal.stringToArrayBuffer(input))) throw new MonoCloudTokenError("JWT signature verification failed");
795
+ if (!await crypto.subtle.verify(keyToSubtle(key), key, signature, require_utils_internal.stringToArrayBuffer(input))) throw new MonoCloudTokenError("JWT signature verification failed");
761
796
  let claims;
762
797
  try {
763
- claims = JSON.parse(require_internal.decodeBase64Url(payload));
798
+ claims = JSON.parse(require_utils_internal.decodeBase64Url(payload));
764
799
  } catch {
765
800
  throw new MonoCloudTokenError("Failed to parse JWT Payload");
766
801
  }
767
802
  if (claims === null || typeof claims !== "object" || Array.isArray(claims)) throw new MonoCloudTokenError("JWT Payload must be a top level object");
768
803
  if ((claims.nonce || nonce) && claims.nonce !== nonce) throw new MonoCloudTokenError("Nonce mismatch");
769
- const current = require_internal.now() + clockSkew;
804
+ const current = require_utils_internal.now() + clockSkew;
770
805
  /* v8 ignore else -- @preserve */
771
806
  if (claims.exp !== void 0) {
772
807
  if (typeof claims.exp !== "number") throw new MonoCloudTokenError("Unexpected JWT \"exp\" (expiration time) claim type");
@@ -787,11 +822,12 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
787
822
  }
788
823
  /**
789
824
  * Decodes the payload of a JSON Web Token (JWT) and returns it as an object.
790
- * **THIS METHOD DOES NOT VERIFY JWT TOKENS**.
791
825
  *
792
- * @param jwt - JWT to decode
826
+ * >Note: THIS METHOD DOES NOT VERIFY JWT TOKENS.
827
+ *
828
+ * @param jwt - JWT to decode.
793
829
  *
794
- * @returns Decoded payload
830
+ * @returns Decoded payload.
795
831
  *
796
832
  * @throws {@link MonoCloudTokenError} - If decoding fails
797
833
  *
@@ -800,7 +836,7 @@ var MonoCloudOidcClient = class MonoCloudOidcClient {
800
836
  try {
801
837
  const [, payload] = jwt.split(".");
802
838
  if (!payload?.trim()) throw new MonoCloudTokenError("JWT does not contain payload");
803
- const decoded = require_internal.decodeBase64Url(payload);
839
+ const decoded = require_utils_internal.decodeBase64Url(payload);
804
840
  if (!decoded.startsWith("{")) throw new MonoCloudTokenError("Payload is not an object");
805
841
  return JSON.parse(decoded);
806
842
  } catch (e) {