@asgardeo/javascript 0.5.0 → 0.5.2

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.
@@ -54,5 +54,7 @@ declare abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoC
54
54
  abstract signUp(payload?: unknown): Promise<void> | Promise<EmbeddedFlowExecuteResponse>;
55
55
  abstract getAccessToken(sessionId?: string): Promise<string>;
56
56
  abstract clearSession(sessionId?: string): void;
57
+ abstract setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void>;
58
+ abstract decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
57
59
  }
58
60
  export default AsgardeoJavaScriptClient;
@@ -16,7 +16,6 @@
16
16
  * under the License.
17
17
  */
18
18
  import { Crypto, JWKInterface } from './models/crypto';
19
- import { IdToken } from './models/token';
20
19
  export declare class IsomorphicCrypto<T = any> {
21
20
  private _cryptoUtils;
22
21
  constructor(cryptoUtils: Crypto<T>);
@@ -60,14 +59,5 @@ export declare class IsomorphicCrypto<T = any> {
60
59
  * @throws
61
60
  */
62
61
  isValidIdToken(idToken: string, jwk: JWKInterface, clientId: string, issuer: string, username: string, clockTolerance: number | undefined, validateJwtIssuer: boolean | undefined): Promise<boolean>;
63
- /**
64
- * This function decodes the payload of an id token and returns it.
65
- *
66
- * @param idToken - The id token to be decoded.
67
- *
68
- * @returns - The decoded payload of the id token.
69
- *
70
- * @throws
71
- */
72
- decodeIdToken(idToken: string): IdToken;
62
+ decodeJwtToken<T = Record<string, unknown>>(token: string): T;
73
63
  }
@@ -189,6 +189,18 @@ export declare class AsgardeoAuthClient<T> {
189
189
  * @preserve
190
190
  */
191
191
  getOpenIDProviderEndpoints(): Promise<Partial<OIDCEndpoints>>;
192
+ /**
193
+ * This method decodes a given JWT token and returns the payload.
194
+ *
195
+ * @param token - The token to be decoded.
196
+ * @returns - A Promise that resolves with the decoded token payload.
197
+ *
198
+ * @example
199
+ * ```
200
+ * const decodedToken = await auth.decodeJwtToken(token);
201
+ * ```
202
+ */
203
+ decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
192
204
  /**
193
205
  * This method decodes the payload of the ID token and returns it.
194
206
  *
package/dist/cjs/index.js CHANGED
@@ -595,22 +595,13 @@ var IsomorphicCrypto = class {
595
595
  return Promise.reject(error2);
596
596
  });
597
597
  }
598
- /**
599
- * This function decodes the payload of an id token and returns it.
600
- *
601
- * @param idToken - The id token to be decoded.
602
- *
603
- * @returns - The decoded payload of the id token.
604
- *
605
- * @throws
606
- */
607
- decodeIdToken(idToken) {
598
+ decodeJwtToken(token) {
608
599
  try {
609
- const utf8String = this._cryptoUtils.base64URLDecode(idToken?.split(".")[1]);
600
+ const utf8String = this._cryptoUtils.base64URLDecode(token?.split(".")[1]);
610
601
  const payload = JSON.parse(utf8String);
611
602
  return payload;
612
603
  } catch (error2) {
613
- throw new AsgardeoAuthException("JS-CRYPTO_UTIL-DIT-IV01", "Decoding ID token failed.", error2);
604
+ throw new AsgardeoAuthException("JS-CRYPTO_UTIL-DIT-IV02", "Decoding token failed.", error2);
614
605
  }
615
606
  }
616
607
  };
@@ -686,6 +677,15 @@ var TokenExchangeConstants = {
686
677
  };
687
678
  var TokenExchangeConstants_default = TokenExchangeConstants;
688
679
 
680
+ // src/models/platforms.ts
681
+ var Platform = /* @__PURE__ */ ((Platform2) => {
682
+ Platform2["Asgardeo"] = "ASGARDEO";
683
+ Platform2["IdentityServer"] = "IDENTITY_SERVER";
684
+ Platform2["AsgardeoV2"] = "AsgardeoV2";
685
+ Platform2["Unknown"] = "UNKNOWN";
686
+ return Platform2;
687
+ })(Platform || {});
688
+
689
689
  // src/utils/extractUserClaimsFromIdToken.ts
690
690
  var extractUserClaimsFromIdToken = (payload) => {
691
691
  const filteredPayload = { ...payload };
@@ -881,6 +881,9 @@ var AuthenticationHelper = class {
881
881
  [OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.TOKEN]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.TOKEN}`,
882
882
  [OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.USERINFO]: `${baseUrl}${OIDCDiscoveryConstants_default.Endpoints.USERINFO}`
883
883
  };
884
+ if (configData.platform === "AsgardeoV2" /* AsgardeoV2 */) {
885
+ defaultEndpoints[OIDCDiscoveryConstants_default.Storage.StorageKeys.Endpoints.ISSUER] = `${baseUrl}`;
886
+ }
884
887
  return { ...defaultEndpoints, ...oidcProviderMetaData };
885
888
  }
886
889
  async validateIdToken(idToken) {
@@ -920,13 +923,13 @@ var AuthenticationHelper = class {
920
923
  jwk,
921
924
  (await this._config()).clientId,
922
925
  issuer ?? "",
923
- this._cryptoHelper.decodeIdToken(idToken).sub,
926
+ this._cryptoHelper.decodeJwtToken(idToken).sub,
924
927
  (await this._config()).tokenValidation?.idToken?.clockTolerance,
925
928
  (await this._config()).tokenValidation?.idToken?.validateIssuer ?? true
926
929
  );
927
930
  }
928
931
  getAuthenticatedUserInfo(idToken) {
929
- const payload = this._cryptoHelper.decodeIdToken(idToken);
932
+ const payload = this._cryptoHelper.decodeJwtToken(idToken);
930
933
  const username = payload?.["username"] ?? "";
931
934
  const givenName = payload?.["given_name"] ?? "";
932
935
  const familyName = payload?.["family_name"] ?? "";
@@ -1492,6 +1495,20 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1492
1495
  userinfoEndpoint: oidcProviderMetaData.userinfo_endpoint ?? ""
1493
1496
  };
1494
1497
  }
1498
+ /**
1499
+ * This method decodes a given JWT token and returns the payload.
1500
+ *
1501
+ * @param token - The token to be decoded.
1502
+ * @returns - A Promise that resolves with the decoded token payload.
1503
+ *
1504
+ * @example
1505
+ * ```
1506
+ * const decodedToken = await auth.decodeJwtToken(token);
1507
+ * ```
1508
+ */
1509
+ async decodeJwtToken(token) {
1510
+ return this._cryptoHelper.decodeJwtToken(token);
1511
+ }
1495
1512
  /**
1496
1513
  * This method decodes the payload of the ID token and returns it.
1497
1514
  *
@@ -1511,7 +1528,7 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1511
1528
  */
1512
1529
  async getDecodedIdToken(userId, idToken) {
1513
1530
  const _idToken = (await this._storageManager.getSessionData(userId)).id_token;
1514
- const payload = this._cryptoHelper.decodeIdToken(_idToken ?? idToken);
1531
+ const payload = this._cryptoHelper.decodeJwtToken(_idToken ?? idToken);
1515
1532
  return payload;
1516
1533
  }
1517
1534
  /**
@@ -3253,15 +3270,6 @@ var VendorConstants = {
3253
3270
  };
3254
3271
  var VendorConstants_default = VendorConstants;
3255
3272
 
3256
- // src/models/platforms.ts
3257
- var Platform = /* @__PURE__ */ ((Platform2) => {
3258
- Platform2["Asgardeo"] = "ASGARDEO";
3259
- Platform2["IdentityServer"] = "IDENTITY_SERVER";
3260
- Platform2["AsgardeoV2"] = "AsgardeoV2";
3261
- Platform2["Unknown"] = "UNKNOWN";
3262
- return Platform2;
3263
- })(Platform || {});
3264
-
3265
3273
  // src/models/embedded-signin-flow.ts
3266
3274
  var EmbeddedSignInFlowStatus2 = /* @__PURE__ */ ((EmbeddedSignInFlowStatus3) => {
3267
3275
  EmbeddedSignInFlowStatus3["FailCompleted"] = "FAIL_COMPLETED";