@asgardeo/javascript 0.10.2 → 0.12.0

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.
@@ -22,6 +22,7 @@ import { AsgardeoClient } from './models/client';
22
22
  import { Config, SignInOptions, SignOutOptions, SignUpOptions } from './models/config';
23
23
  import { Crypto } from './models/crypto';
24
24
  import { EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse } from './models/embedded-flow';
25
+ import { OIDCDiscoveryApiResponse } from './models/oidc-discovery';
25
26
  import { AllOrganizationsApiResponse, Organization } from './models/organization';
26
27
  import { Storage } from './models/store';
27
28
  import { TokenExchangeRequestConfig, TokenResponse } from './models/token';
@@ -33,6 +34,7 @@ declare class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T>
33
34
  private storageManager;
34
35
  private baseURL;
35
36
  constructor(config?: AuthClientConfig<T>, cacheStore?: Storage, cryptoUtils?: Crypto);
37
+ getDiscoveryResponse(): Promise<OIDCDiscoveryApiResponse | null>;
36
38
  switchOrganization(_organization: Organization, _sessionId?: string): Promise<TokenResponse | Response>;
37
39
  initialize(_config: T, _storage?: Storage): Promise<boolean>;
38
40
  reInitialize(_config: Partial<T>): Promise<boolean>;
@@ -17,6 +17,7 @@
17
17
  */
18
18
  import { OAuthResponseMode } from '../../models/oauth-response';
19
19
  import { OIDCEndpoints } from '../../models/oidc-endpoints';
20
+ import { Platform } from '../../models/platforms';
20
21
  export interface DefaultAuthClientConfig {
21
22
  afterSignInUrl: string;
22
23
  afterSignOutUrl?: string;
@@ -40,6 +41,12 @@ export interface DefaultAuthClientConfig {
40
41
  */
41
42
  targetOrganizationId?: string;
42
43
  };
44
+ /**
45
+ * Optional platform where the application is running.
46
+ * This helps the SDK to optimize its behavior based on the platform.
47
+ * If not provided, the SDK will attempt to auto-detect the platform.
48
+ */
49
+ platform?: keyof typeof Platform;
43
50
  prompt?: string;
44
51
  responseMode?: OAuthResponseMode;
45
52
  scopes?: string | string[] | undefined;
package/dist/cjs/index.js CHANGED
@@ -761,6 +761,23 @@ var PKCEConstants = {
761
761
  };
762
762
  var PKCEConstants_default = PKCEConstants;
763
763
 
764
+ // src/constants/v2/OIDCDiscoveryConstants.ts
765
+ var OIDCDiscoveryConstants2 = {
766
+ /**
767
+ * Collection of standard OIDC endpoint paths used for authentication flows.
768
+ * These endpoints are relative paths that should be appended to the base URL
769
+ * of your identity provider.
770
+ */
771
+ Endpoints: {
772
+ /**
773
+ * OpenID Connect discovery document endpoint.
774
+ * Used to fetch provider metadata from the authorization server.
775
+ */
776
+ WELL_KNOWN: "/.well-known/openid-configuration"
777
+ }
778
+ };
779
+ var OIDCDiscoveryConstants_default2 = OIDCDiscoveryConstants2;
780
+
764
781
  // src/constants/TokenConstants.ts
765
782
  var TokenConstants = {
766
783
  /**
@@ -1242,7 +1259,8 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1242
1259
  this.configProvider = async () => this.storageManager.getConfigData();
1243
1260
  this.oidcProviderMetaDataProvider = async () => this.storageManager.loadOpenIDProviderConfiguration();
1244
1261
  _AsgardeoAuthClient.authHelperInstance = this.authHelper;
1245
- let { applicationId } = config;
1262
+ const { applicationId, platform, endpoints } = config;
1263
+ let resolvedApplicationId = applicationId;
1246
1264
  if (applicationId) {
1247
1265
  await this.storageManager.setPersistedData({
1248
1266
  applicationId
@@ -1250,13 +1268,20 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1250
1268
  } else {
1251
1269
  const persistedData = await this.storageManager.getPersistedData();
1252
1270
  if (persistedData["applicationId"]) {
1253
- applicationId = persistedData["applicationId"];
1271
+ resolvedApplicationId = persistedData["applicationId"];
1272
+ }
1273
+ }
1274
+ const resolvedEndpoints = endpoints || {};
1275
+ if (platform === "AsgardeoV2" /* AsgardeoV2 */) {
1276
+ if (!resolvedEndpoints["wellKnown"]) {
1277
+ resolvedEndpoints["wellKnown"] = OIDCDiscoveryConstants_default2.Endpoints.WELL_KNOWN;
1254
1278
  }
1255
1279
  }
1256
1280
  await this.storageManager.setConfigData({
1257
1281
  ...DefaultConfig,
1258
1282
  ...config,
1259
- applicationId,
1283
+ applicationId: resolvedApplicationId,
1284
+ endpoints: resolvedEndpoints,
1260
1285
  scope: processOpenIDScopes_default(config.scopes)
1261
1286
  });
1262
1287
  }
@@ -1472,11 +1497,12 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1472
1497
  )) {
1473
1498
  return Promise.resolve();
1474
1499
  }
1475
- const { wellKnownEndpoint } = configData;
1476
- if (wellKnownEndpoint) {
1500
+ const { wellKnownEndpoint, platform, discovery, baseUrl, endpoints } = configData;
1501
+ const resolvedWellKnownEndpoint = wellKnownEndpoint || (platform === "AsgardeoV2" /* AsgardeoV2 */ && discovery?.wellKnown?.enabled ? `${baseUrl}${endpoints?.wellKnown ?? "/.well-known/openid-configuration"}` : void 0);
1502
+ if (resolvedWellKnownEndpoint) {
1477
1503
  let response;
1478
1504
  try {
1479
- response = await fetch(wellKnownEndpoint);
1505
+ response = await fetch(resolvedWellKnownEndpoint);
1480
1506
  if (response.status !== 200 || !response.ok) {
1481
1507
  throw new Error();
1482
1508
  }
@@ -3645,6 +3671,12 @@ var AsgardeoJavaScriptClient = class {
3645
3671
  }
3646
3672
  this.baseURL = config?.baseUrl ?? "";
3647
3673
  }
3674
+ async getDiscoveryResponse() {
3675
+ if (!this.storageManager) {
3676
+ return null;
3677
+ }
3678
+ return this.storageManager.loadOpenIDProviderConfiguration();
3679
+ }
3648
3680
  /* eslint-disable class-methods-use-this, @typescript-eslint/no-unused-vars */
3649
3681
  switchOrganization(_organization, _sessionId) {
3650
3682
  throw new Error("Method not implemented.");