@asgardeo/react 0.9.0 → 0.9.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.
@@ -64,5 +64,7 @@ declare class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactC
64
64
  requestAll(requestConfigs?: HttpRequestConfig[]): Promise<HttpResponse<any>[]>;
65
65
  getAccessToken(sessionId?: string): Promise<string>;
66
66
  clearSession(sessionId?: string): void;
67
+ setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void>;
68
+ decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
67
69
  }
68
70
  export default AsgardeoReactClient;
@@ -44,6 +44,7 @@ declare class AuthAPI {
44
44
  * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
45
45
  */
46
46
  getConfigData(): Promise<AuthClientConfig<Config>>;
47
+ getStorageManager(): Promise<any>;
47
48
  /**
48
49
  * Method to get the configuration data.
49
50
  *
@@ -129,6 +130,13 @@ declare class AuthAPI {
129
130
  * @return {HttpClientInstance} - The Axios HTTP client.
130
131
  */
131
132
  getHttpClient(): Promise<HttpClientInstance>;
133
+ /**
134
+ * This method decodes a JWT token payload and returns it.
135
+ *
136
+ * @param token - The token to decode.
137
+ * @returns The decoded token payload.
138
+ */
139
+ decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
132
140
  /**
133
141
  * This method decodes the payload of the id token and returns it.
134
142
  *
package/dist/cjs/index.js CHANGED
@@ -254,6 +254,9 @@ var _AuthAPI = class _AuthAPI {
254
254
  async getConfigData() {
255
255
  return this._client.getConfigData();
256
256
  }
257
+ async getStorageManager() {
258
+ return this._client.getStorageManager();
259
+ }
257
260
  /**
258
261
  * Method to get the configuration data.
259
262
  *
@@ -402,6 +405,15 @@ var _AuthAPI = class _AuthAPI {
402
405
  async getHttpClient() {
403
406
  return this._client.getHttpClient();
404
407
  }
408
+ /**
409
+ * This method decodes a JWT token payload and returns it.
410
+ *
411
+ * @param token - The token to decode.
412
+ * @returns The decoded token payload.
413
+ */
414
+ async decodeJwtToken(token) {
415
+ return this._client.decodeJwtToken(token);
416
+ }
405
417
  /**
406
418
  * This method decodes the payload of the id token and returns it.
407
419
  *
@@ -876,12 +888,26 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
876
888
  const authId = authIdFromUrl || authIdFromStorage;
877
889
  const baseUrlFromStorage = sessionStorage.getItem("asgardeo_base_url");
878
890
  const baseUrl = config?.baseUrl || baseUrlFromStorage;
879
- return (0, import_browser6.executeEmbeddedSignInFlowV2)({
891
+ const response = await (0, import_browser6.executeEmbeddedSignInFlowV2)({
880
892
  payload: arg1,
881
893
  url: arg2?.url,
882
894
  baseUrl,
883
895
  authId
884
896
  });
897
+ if (isV2Platform && response && typeof response === "object" && response["flowStatus"] === import_browser6.EmbeddedSignInFlowStatusV2.Complete && response["assertion"]) {
898
+ const decodedAssertion = await this.decodeJwtToken(response["assertion"]);
899
+ const createdAt = decodedAssertion.iat ? decodedAssertion.iat * 1e3 : Date.now();
900
+ const expiresIn = decodedAssertion.exp && decodedAssertion.iat ? decodedAssertion.exp - decodedAssertion.iat : 3600;
901
+ await this.setSession({
902
+ access_token: response["assertion"],
903
+ id_token: response["assertion"],
904
+ token_type: "Bearer",
905
+ expires_in: expiresIn,
906
+ created_at: createdAt,
907
+ scope: decodedAssertion.scope
908
+ });
909
+ }
910
+ return response;
885
911
  }
886
912
  if (typeof arg1 === "object" && "flowId" in arg1 && typeof arg2 === "object" && "url" in arg2) {
887
913
  return (0, import_browser6.executeEmbeddedSignInFlow)({
@@ -913,8 +939,15 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
913
939
  const firstArg = args[0];
914
940
  const baseUrl = config?.baseUrl;
915
941
  if (config.platform === import_browser6.Platform.AsgardeoV2) {
942
+ const authIdFromUrl = new URL(window.location.href).searchParams.get("authId");
943
+ const authIdFromStorage = sessionStorage.getItem("asgardeo_auth_id");
944
+ const authId = authIdFromUrl || authIdFromStorage;
945
+ if (authIdFromUrl && !authIdFromStorage) {
946
+ sessionStorage.setItem("asgardeo_auth_id", authIdFromUrl);
947
+ }
916
948
  return (0, import_browser6.executeEmbeddedSignUpFlowV2)({
917
949
  baseUrl,
950
+ authId,
918
951
  payload: typeof firstArg === "object" && "flowType" in firstArg ? { ...firstArg, verbose: true } : firstArg
919
952
  });
920
953
  }
@@ -938,6 +971,12 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
938
971
  clearSession(sessionId) {
939
972
  this.asgardeo.clearSession(sessionId);
940
973
  }
974
+ async setSession(sessionData, sessionId) {
975
+ return await (await this.asgardeo.getStorageManager()).setSessionData(sessionData, sessionId);
976
+ }
977
+ decodeJwtToken(token) {
978
+ return this.asgardeo.decodeJwtToken(token);
979
+ }
941
980
  };
942
981
  var AsgardeoReactClient_default = AsgardeoReactClient;
943
982
 
@@ -7614,7 +7653,6 @@ var BaseSignInContent2 = ({
7614
7653
  setIsSubmitting(true);
7615
7654
  setApiError(null);
7616
7655
  clearMessages();
7617
- console.log("Submitting component:", component, "with data:", data);
7618
7656
  try {
7619
7657
  const filteredInputs = {};
7620
7658
  if (data) {
@@ -10095,6 +10133,11 @@ var SignUp2 = ({
10095
10133
  const handleOnSubmit = async (payload) => await signUp(payload);
10096
10134
  const handleComplete = (response) => {
10097
10135
  onComplete?.(response);
10136
+ const oauthRedirectUrl = response?.redirectUrl;
10137
+ if (shouldRedirectAfterSignUp && oauthRedirectUrl) {
10138
+ window.location.href = oauthRedirectUrl;
10139
+ return;
10140
+ }
10098
10141
  if (shouldRedirectAfterSignUp && response?.type !== import_browser63.EmbeddedFlowResponseType.Redirection && afterSignUpUrl) {
10099
10142
  window.location.href = afterSignUpUrl;
10100
10143
  }