@asgardeo/react 0.16.2 → 0.18.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.
@@ -15,7 +15,7 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { FlowMetadataResponse, HttpRequestConfig, HttpResponse, IdToken, Organization, SignInOptions, TokenExchangeRequestConfig, TokenResponse } from '@asgardeo/browser';
18
+ import { FlowMetadataResponse, HttpRequestConfig, HttpResponse, IdToken, OIDCDiscoveryApiResponse, Organization, SignInOptions, TokenExchangeRequestConfig, TokenResponse } from '@asgardeo/browser';
19
19
  import { Context } from 'react';
20
20
  import AsgardeoReactClient from '../../AsgardeoReactClient';
21
21
  import { AsgardeoReactConfig } from '../../models/config';
@@ -27,6 +27,17 @@ export type AsgardeoContextProps = {
27
27
  applicationId: string | undefined;
28
28
  baseUrl: string | undefined;
29
29
  clientId: string | undefined;
30
+ /**
31
+ * OIDC discovery data.
32
+ */
33
+ discovery: {
34
+ /**
35
+ * The response from the `.well-known/openid-configuration` endpoint.
36
+ * Contains server capabilities, supported endpoints, and metadata.
37
+ * `null` while loading or when discovery has not been fetched.
38
+ */
39
+ wellKnown: OIDCDiscoveryApiResponse | null;
40
+ };
30
41
  /**
31
42
  * Swaps the current access token with a new one based on the provided configuration (with a grant type).
32
43
  * @param config - Configuration for the token exchange request.
package/dist/index.js CHANGED
@@ -22,6 +22,9 @@ var AsgardeoContext = createContext({
22
22
  clearSession: () => {
23
23
  },
24
24
  clientId: void 0,
25
+ discovery: {
26
+ wellKnown: null
27
+ },
25
28
  exchangeToken: null,
26
29
  getAccessToken: null,
27
30
  getDecodedIdToken: null,
@@ -612,9 +615,10 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
612
615
  if (!resolvedOrganizationHandle) {
613
616
  resolvedOrganizationHandle = deriveOrganizationHandleFromBaseUrl(config?.baseUrl);
614
617
  }
615
- return this.withLoading(
616
- async () => this.asgardeo.init({ ...config, organizationHandle: resolvedOrganizationHandle })
617
- );
618
+ return this.withLoading(async () => {
619
+ this.initializeConfig = { ...config, organizationHandle: resolvedOrganizationHandle };
620
+ return this.asgardeo.init(this.initializeConfig);
621
+ });
618
622
  }
619
623
  reInitialize(config) {
620
624
  return this.withLoading(async () => {
@@ -886,6 +890,10 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
886
890
  navigate(getRedirectBasedSignUpUrl(config));
887
891
  return void 0;
888
892
  }
893
+ async getDiscoveryResponse() {
894
+ const storageManager = await this.asgardeo.getStorageManager();
895
+ return storageManager.loadOpenIDProviderConfiguration();
896
+ }
889
897
  async request(requestConfig) {
890
898
  return this.asgardeo.httpRequest(requestConfig);
891
899
  }
@@ -2034,6 +2042,7 @@ var AsgardeoProvider = ({
2034
2042
  ...rest
2035
2043
  });
2036
2044
  const [isUpdatingSession, setIsUpdatingSession] = useState8(false);
2045
+ const [wellKnown, setWellKnown] = useState8(null);
2037
2046
  const [brandingPreference, setBrandingPreference] = useState8(null);
2038
2047
  const [isBrandingLoading, setIsBrandingLoading] = useState8(false);
2039
2048
  const [brandingError, setBrandingError] = useState8(null);
@@ -2051,6 +2060,7 @@ var AsgardeoProvider = ({
2051
2060
  await asgardeo.initialize(config);
2052
2061
  const initializedConfig = await asgardeo.getConfiguration();
2053
2062
  setConfig(initializedConfig);
2063
+ setWellKnown(await asgardeo.getDiscoveryResponse());
2054
2064
  })();
2055
2065
  }, []);
2056
2066
  async function updateSession() {
@@ -2072,25 +2082,31 @@ var AsgardeoProvider = ({
2072
2082
  schemas: []
2073
2083
  });
2074
2084
  } else {
2075
- try {
2076
- const fetchedUser = await asgardeo.getUser({ baseUrl: resolvedBaseUrl });
2077
- setUser(fetchedUser);
2078
- } catch (error) {
2079
- }
2080
- try {
2081
- const fetchedUserProfile = await asgardeo.getUserProfile({ baseUrl: resolvedBaseUrl });
2082
- setUserProfile(fetchedUserProfile);
2083
- } catch (error) {
2084
- }
2085
- try {
2086
- const fetchedOrganization = await asgardeo.getCurrentOrganization();
2087
- setCurrentOrganization(fetchedOrganization);
2088
- } catch (error) {
2085
+ const shouldFetchUserProfile = preferences?.user?.fetchUserProfile !== false;
2086
+ if (shouldFetchUserProfile) {
2087
+ try {
2088
+ const fetchedUser = await asgardeo.getUser({ baseUrl: resolvedBaseUrl });
2089
+ setUser(fetchedUser);
2090
+ } catch (error) {
2091
+ }
2092
+ try {
2093
+ const fetchedUserProfile = await asgardeo.getUserProfile({ baseUrl: resolvedBaseUrl });
2094
+ setUserProfile(fetchedUserProfile);
2095
+ } catch (error) {
2096
+ }
2089
2097
  }
2090
- try {
2091
- const fetchedMyOrganizations = await asgardeo.getMyOrganizations();
2092
- setMyOrganizations(fetchedMyOrganizations);
2093
- } catch (error) {
2098
+ const shouldFetchOrganizations = preferences?.user?.fetchOrganizations !== false;
2099
+ if (shouldFetchOrganizations) {
2100
+ try {
2101
+ const fetchedOrganization = await asgardeo.getCurrentOrganization();
2102
+ setCurrentOrganization(fetchedOrganization);
2103
+ } catch (error) {
2104
+ }
2105
+ try {
2106
+ const fetchedMyOrganizations = await asgardeo.getMyOrganizations();
2107
+ setMyOrganizations(fetchedMyOrganizations);
2108
+ } catch (error) {
2109
+ }
2094
2110
  }
2095
2111
  }
2096
2112
  const currentSignInStatus = await asgardeo.isSignedIn();
@@ -2369,6 +2385,9 @@ var AsgardeoProvider = ({
2369
2385
  baseUrl,
2370
2386
  clearSession,
2371
2387
  clientId,
2388
+ discovery: {
2389
+ wellKnown
2390
+ },
2372
2391
  exchangeToken,
2373
2392
  getAccessToken,
2374
2393
  getDecodedIdToken,
@@ -2405,6 +2424,7 @@ var AsgardeoProvider = ({
2405
2424
  afterSignInUrl,
2406
2425
  baseUrl,
2407
2426
  clientId,
2427
+ wellKnown,
2408
2428
  isInitializedSync,
2409
2429
  isLoadingSync,
2410
2430
  isSignedInSync,