@asgardeo/javascript 0.1.20 → 0.1.21

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.
@@ -53,5 +53,6 @@ declare abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoC
53
53
  abstract signUp(payload: EmbeddedFlowExecuteRequestPayload): Promise<EmbeddedFlowExecuteResponse>;
54
54
  abstract signUp(payload?: unknown): Promise<void> | Promise<EmbeddedFlowExecuteResponse>;
55
55
  abstract getAccessToken(sessionId?: string): Promise<string>;
56
+ abstract clearSession(sessionId?: string): void;
56
57
  }
57
58
  export default AsgardeoJavaScriptClient;
@@ -21,7 +21,7 @@ export interface DefaultAuthClientConfig {
21
21
  afterSignInUrl: string;
22
22
  afterSignOutUrl?: string;
23
23
  clientHost?: string;
24
- clientId: string;
24
+ clientId?: string;
25
25
  clientSecret?: string;
26
26
  enablePKCE?: boolean;
27
27
  prompt?: string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { EmbeddedFlowExecuteRequestConfigV2, EmbeddedSignInFlowResponseV2 } from '../../models/v2/embedded-signin-flow-v2';
19
+ declare const executeEmbeddedSignInFlowV2: ({ url, baseUrl, payload, sessionDataKey, ...requestConfig }: EmbeddedFlowExecuteRequestConfigV2) => Promise<EmbeddedSignInFlowResponseV2>;
20
+ export default executeEmbeddedSignInFlowV2;
package/dist/cjs/index.js CHANGED
@@ -37,8 +37,10 @@ __export(index_exports, {
37
37
  EmbeddedSignInFlowAuthenticatorParamType: () => EmbeddedSignInFlowAuthenticatorParamType,
38
38
  EmbeddedSignInFlowAuthenticatorPromptType: () => EmbeddedSignInFlowAuthenticatorPromptType,
39
39
  EmbeddedSignInFlowStatus: () => EmbeddedSignInFlowStatus,
40
+ EmbeddedSignInFlowStatusV2: () => EmbeddedSignInFlowStatusV2,
40
41
  EmbeddedSignInFlowStepType: () => EmbeddedSignInFlowStepType,
41
42
  EmbeddedSignInFlowType: () => EmbeddedSignInFlowType,
43
+ EmbeddedSignInFlowTypeV2: () => EmbeddedSignInFlowTypeV2,
42
44
  FieldType: () => FieldType,
43
45
  FlowMode: () => FlowMode,
44
46
  IsomorphicCrypto: () => IsomorphicCrypto,
@@ -48,6 +50,8 @@ __export(index_exports, {
48
50
  TokenConstants: () => TokenConstants_default,
49
51
  VendorConstants: () => VendorConstants_default,
50
52
  WellKnownSchemaIds: () => WellKnownSchemaIds,
53
+ arrayBufferToBase64url: () => arrayBufferToBase64url_default,
54
+ base64urlToArrayBuffer: () => base64urlToArrayBuffer_default,
51
55
  bem: () => bem_default,
52
56
  configureLogger: () => configure,
53
57
  createComponentLogger: () => createComponentLogger,
@@ -62,6 +66,7 @@ __export(index_exports, {
62
66
  deriveOrganizationHandleFromBaseUrl: () => deriveOrganizationHandleFromBaseUrl_default,
63
67
  error: () => error,
64
68
  executeEmbeddedSignInFlow: () => executeEmbeddedSignInFlow_default,
69
+ executeEmbeddedSignInFlowV2: () => executeEmbeddedSignInFlowV2_default,
65
70
  executeEmbeddedSignUpFlow: () => executeEmbeddedSignUpFlow_default,
66
71
  extractPkceStorageKeyFromState: () => extractPkceStorageKeyFromState_default,
67
72
  extractUserClaimsFromIdToken: () => extractUserClaimsFromIdToken_default,
@@ -2107,6 +2112,7 @@ var executeEmbeddedSignInFlow_default = executeEmbeddedSignInFlow;
2107
2112
 
2108
2113
  // src/models/embedded-flow.ts
2109
2114
  var EmbeddedFlowType = /* @__PURE__ */ ((EmbeddedFlowType2) => {
2115
+ EmbeddedFlowType2["Authentication"] = "AUTHENTICATION";
2110
2116
  EmbeddedFlowType2["Registration"] = "REGISTRATION";
2111
2117
  return EmbeddedFlowType2;
2112
2118
  })(EmbeddedFlowType || {});
@@ -2876,6 +2882,102 @@ var getBrandingPreference = async ({
2876
2882
  };
2877
2883
  var getBrandingPreference_default = getBrandingPreference;
2878
2884
 
2885
+ // src/models/v2/embedded-signin-flow-v2.ts
2886
+ var EmbeddedSignInFlowStatusV2 = /* @__PURE__ */ ((EmbeddedSignInFlowStatusV22) => {
2887
+ EmbeddedSignInFlowStatusV22["Complete"] = "COMPLETE";
2888
+ EmbeddedSignInFlowStatusV22["Incomplete"] = "INCOMPLETE";
2889
+ EmbeddedSignInFlowStatusV22["Error"] = "ERROR";
2890
+ return EmbeddedSignInFlowStatusV22;
2891
+ })(EmbeddedSignInFlowStatusV2 || {});
2892
+ var EmbeddedSignInFlowTypeV2 = /* @__PURE__ */ ((EmbeddedSignInFlowTypeV22) => {
2893
+ EmbeddedSignInFlowTypeV22["Redirection"] = "REDIRECTION";
2894
+ EmbeddedSignInFlowTypeV22["View"] = "VIEW";
2895
+ return EmbeddedSignInFlowTypeV22;
2896
+ })(EmbeddedSignInFlowTypeV2 || {});
2897
+
2898
+ // src/api/v2/executeEmbeddedSignInFlowV2.ts
2899
+ var executeEmbeddedSignInFlowV2 = async ({
2900
+ url,
2901
+ baseUrl,
2902
+ payload,
2903
+ sessionDataKey,
2904
+ ...requestConfig
2905
+ }) => {
2906
+ if (!payload) {
2907
+ throw new AsgardeoAPIError(
2908
+ "Authorization payload is required",
2909
+ "executeEmbeddedSignInFlow-ValidationError-002",
2910
+ "javascript",
2911
+ 400,
2912
+ "If an authorization payload is not provided, the request cannot be constructed correctly."
2913
+ );
2914
+ }
2915
+ let endpoint = url ?? `${baseUrl}/flow/execute`;
2916
+ const response = await fetch(endpoint, {
2917
+ ...requestConfig,
2918
+ method: requestConfig.method || "POST",
2919
+ headers: {
2920
+ "Content-Type": "application/json",
2921
+ Accept: "application/json",
2922
+ ...requestConfig.headers
2923
+ },
2924
+ body: JSON.stringify(payload)
2925
+ });
2926
+ if (!response.ok) {
2927
+ const errorText = await response.text();
2928
+ throw new AsgardeoAPIError(
2929
+ `Authorization request failed: ${errorText}`,
2930
+ "executeEmbeddedSignInFlow-ResponseError-001",
2931
+ "javascript",
2932
+ response.status,
2933
+ response.statusText
2934
+ );
2935
+ }
2936
+ const flowResponse = await response.json();
2937
+ if (flowResponse.flowStatus === "COMPLETE" /* Complete */ && flowResponse.assertion && sessionDataKey) {
2938
+ try {
2939
+ const oauth2Response = await fetch(`${baseUrl}/oauth2/authorize`, {
2940
+ method: "POST",
2941
+ headers: {
2942
+ "Content-Type": "application/json",
2943
+ Accept: "application/json",
2944
+ ...requestConfig.headers
2945
+ },
2946
+ body: JSON.stringify({
2947
+ assertion: flowResponse.assertion,
2948
+ sessionDataKey
2949
+ }),
2950
+ credentials: "include"
2951
+ });
2952
+ if (!oauth2Response.ok) {
2953
+ const oauth2ErrorText = await oauth2Response.text();
2954
+ throw new AsgardeoAPIError(
2955
+ `OAuth2 authorization failed: ${oauth2ErrorText}`,
2956
+ "executeEmbeddedSignInFlow-OAuth2Error-002",
2957
+ "javascript",
2958
+ oauth2Response.status,
2959
+ oauth2Response.statusText
2960
+ );
2961
+ }
2962
+ const oauth2Result = await oauth2Response.json();
2963
+ return {
2964
+ flowStatus: flowResponse.flowStatus,
2965
+ redirectUrl: oauth2Result.redirect_uri
2966
+ };
2967
+ } catch (authError) {
2968
+ throw new AsgardeoAPIError(
2969
+ `OAuth2 authorization failed: ${authError instanceof Error ? authError.message : "Unknown error"}`,
2970
+ "executeEmbeddedSignInFlow-OAuth2Error-001",
2971
+ "javascript",
2972
+ 500,
2973
+ "Failed to complete OAuth2 authorization after successful embedded sign-in flow."
2974
+ );
2975
+ }
2976
+ }
2977
+ return flowResponse;
2978
+ };
2979
+ var executeEmbeddedSignInFlowV2_default = executeEmbeddedSignInFlowV2;
2980
+
2879
2981
  // src/constants/ApplicationNativeAuthenticationConstants.ts
2880
2982
  var ApplicationNativeAuthenticationConstants = {
2881
2983
  SupportedAuthenticators: {
@@ -2910,6 +3012,7 @@ var VendorConstants_default = VendorConstants;
2910
3012
  var Platform = /* @__PURE__ */ ((Platform2) => {
2911
3013
  Platform2["Asgardeo"] = "ASGARDEO";
2912
3014
  Platform2["IdentityServer"] = "IDENTITY_SERVER";
3015
+ Platform2["AsgardeoV2"] = "AsgardeoV2";
2913
3016
  Platform2["Unknown"] = "UNKNOWN";
2914
3017
  return Platform2;
2915
3018
  })(Platform || {});
@@ -3564,6 +3667,30 @@ var createTheme = (config = {}, isDark = false) => {
3564
3667
  var DEFAULT_THEME = "light";
3565
3668
  var createTheme_default = createTheme;
3566
3669
 
3670
+ // src/utils/arrayBufferToBase64url.ts
3671
+ var arrayBufferToBase64url = (buffer) => {
3672
+ const bytes = new Uint8Array(buffer);
3673
+ let binary = "";
3674
+ for (let i = 0; i < bytes.byteLength; i++) {
3675
+ binary += String.fromCharCode(bytes[i]);
3676
+ }
3677
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
3678
+ };
3679
+ var arrayBufferToBase64url_default = arrayBufferToBase64url;
3680
+
3681
+ // src/utils/base64urlToArrayBuffer.ts
3682
+ var base64urlToArrayBuffer = (base64url) => {
3683
+ const padding = "=".repeat((4 - base64url.length % 4) % 4);
3684
+ const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/") + padding;
3685
+ const binaryString = atob(base64);
3686
+ const bytes = new Uint8Array(binaryString.length);
3687
+ for (let i = 0; i < binaryString.length; i++) {
3688
+ bytes[i] = binaryString.charCodeAt(i);
3689
+ }
3690
+ return bytes.buffer;
3691
+ };
3692
+ var base64urlToArrayBuffer_default = base64urlToArrayBuffer;
3693
+
3567
3694
  // src/utils/bem.ts
3568
3695
  var bem = (baseClass, element, modifier) => {
3569
3696
  let className = baseClass;
@@ -4412,8 +4539,10 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
4412
4539
  EmbeddedSignInFlowAuthenticatorParamType,
4413
4540
  EmbeddedSignInFlowAuthenticatorPromptType,
4414
4541
  EmbeddedSignInFlowStatus,
4542
+ EmbeddedSignInFlowStatusV2,
4415
4543
  EmbeddedSignInFlowStepType,
4416
4544
  EmbeddedSignInFlowType,
4545
+ EmbeddedSignInFlowTypeV2,
4417
4546
  FieldType,
4418
4547
  FlowMode,
4419
4548
  IsomorphicCrypto,
@@ -4423,6 +4552,8 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
4423
4552
  TokenConstants,
4424
4553
  VendorConstants,
4425
4554
  WellKnownSchemaIds,
4555
+ arrayBufferToBase64url,
4556
+ base64urlToArrayBuffer,
4426
4557
  bem,
4427
4558
  configureLogger,
4428
4559
  createComponentLogger,
@@ -4437,6 +4568,7 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
4437
4568
  deriveOrganizationHandleFromBaseUrl,
4438
4569
  error,
4439
4570
  executeEmbeddedSignInFlow,
4571
+ executeEmbeddedSignInFlowV2,
4440
4572
  executeEmbeddedSignUpFlow,
4441
4573
  extractPkceStorageKeyFromState,
4442
4574
  extractUserClaimsFromIdToken,