@asgardeo/react 0.1.1 → 0.2.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.
package/dist/cjs/index.js CHANGED
@@ -40400,7 +40400,7 @@ const BrandingPreferenceContext = React$1.createContext(undefined);
40400
40400
  */
40401
40401
  const useAuthentication = () => {
40402
40402
  const contextValue = React$1.useContext(AsgardeoContext);
40403
- const { user, isAuthenticated, accessToken } = contextValue;
40403
+ const { user, isAuthenticated, accessToken, authResponse } = contextValue;
40404
40404
  const signOut$1 = () => {
40405
40405
  signOut().then(() => {
40406
40406
  sessionStorage.clear();
@@ -40409,7 +40409,13 @@ const useAuthentication = () => {
40409
40409
  }
40410
40410
  });
40411
40411
  };
40412
- return { accessToken, isAuthenticated, signOut: signOut$1, user };
40412
+ return {
40413
+ accessToken,
40414
+ authResponse,
40415
+ isAuthenticated,
40416
+ signOut: signOut$1,
40417
+ user,
40418
+ };
40413
40419
  };
40414
40420
 
40415
40421
  /**
@@ -44288,6 +44294,39 @@ class SPACryptoUtils {
44288
44294
  var css$1 = "/**\n * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n.Box-asgardeoSignIn {\n min-width: 350px;\n min-height: 75vh;\n}\n.Box-asgardeoSignIn .email-otp-resend-button {\n margin-top: 0;\n}\n.Box-asgardeoSignIn .multiple-otions-title {\n margin: 16px 0 34px;\n}\n.Box-asgardeoSignIn .asgardeo-multiple-options-paper {\n padding-bottom: 64px;\n}\n.Box-asgardeoSignIn .asgardeo-multiple-options-paper .asgardeo-sign-in-alert {\n margin-bottom: 24px;\n}\n\n.Box-circularProgressHolder {\n display: flex;\n justify-content: center;\n align-items: center;\n min-height: 75vh;\n}\n.Box-circularProgressHolder .circular-progress {\n color: rgb(214, 211, 211) !important;\n}\n\n.asgardeo-sign-in-footer,\n.asgardeo-sign-in-logo {\n opacity: 0.5;\n animation: fade-in 0.7s ease-in-out forwards;\n}\n\n@keyframes fade-in {\n to {\n opacity: 1;\n }\n}\n.circular-progress-holder-authn {\n display: flex;\n justify-content: center;\n align-items: center;\n flex-grow: 1;\n}\n.circular-progress-holder-authn .sign-in-button-progress {\n color: var(--oxygen-palette-primary-main);\n margin: 0 auto !important;\n max-height: 25px;\n max-width: 25px;\n margin-left: 12px;\n}";
44289
44295
  n(css$1,{});
44290
44296
 
44297
+ /**
44298
+ * This component renders the IdentifierFirst authentication form.
44299
+ *
44300
+ * @param {IdentifierFirstProps} props - Props injected to the IdentifierFirst authentication component.
44301
+ * @param {BrandingProps} props.brandingProps - Branding props.
44302
+ * @param {Function} props.handleAuthenticate - Callback to handle authentication.
44303
+ * @param {Authenticator} props.authenticator - Authenticator.
44304
+ * @param {AlertType} props.alert - Alert type.
44305
+ * @param {ReactElement[]} props.renderLoginOptions - Login options.
44306
+ * @param {boolean} props.showSelfSignUp - Show self sign up.
44307
+ *
44308
+ * @return {ReactElement}
44309
+ */
44310
+ const IdentifierFirst = ({ handleAuthenticate, authenticator, alert, brandingProps, showSelfSignUp, renderLoginOptions, }) => {
44311
+ var _a;
44312
+ const [username, setUsername] = React$1.useState('');
44313
+ const { isAuthLoading } = React$1.useContext(AsgardeoContext);
44314
+ const { t, isLoading } = useTranslations({
44315
+ componentLocaleOverride: brandingProps === null || brandingProps === void 0 ? void 0 : brandingProps.locale,
44316
+ componentTextOverrides: (_a = brandingProps === null || brandingProps === void 0 ? void 0 : brandingProps.preference) === null || _a === void 0 ? void 0 : _a.text,
44317
+ screen: ScreenType.Login,
44318
+ });
44319
+ if (isLoading) {
44320
+ return (jsxRuntimeExports.jsxs(SignIn$1.Paper, { className: "asgardeo-basic-auth-skeleton", children: [jsxRuntimeExports.jsx(Pi, { className: "skeleton-title", variant: "text", width: 100, height: 55 }), jsxRuntimeExports.jsx(Pi, { className: "skeleton-text-field-label", variant: "text", width: 70 }), jsxRuntimeExports.jsx(Pi, { variant: "rectangular", width: 300, height: 40 }), jsxRuntimeExports.jsx(Pi, { className: "skeleton-text-field-label", variant: "text", width: 70 }), jsxRuntimeExports.jsx(Pi, { variant: "rectangular", width: 300, height: 40 }), jsxRuntimeExports.jsx(Pi, { className: "skeleton-submit-button", variant: "rectangular", width: 270, height: 40 })] }));
44321
+ }
44322
+ return (jsxRuntimeExports.jsxs(SignIn$1.Paper, { className: "Paper-basicAuth", children: [jsxRuntimeExports.jsx(SignIn$1.Typography, { title: true, className: "Typography-basicAuthTitle", children: t(keys.login.login.heading) }), alert && (jsxRuntimeExports.jsx(SignIn$1.Alert, Object.assign({ className: "asgardeo-basic-auth-alert" }, alert === null || alert === void 0 ? void 0 : alert.alertType, { children: t(alert.key) }))), jsxRuntimeExports.jsx(SignIn$1.TextField, { fullWidth: true, autoComplete: "off", label: t(keys.login.username), name: "text", value: username, placeholder: t(keys.login.enter.your.username), onChange: (e) => setUsername(e.target.value) }), jsxRuntimeExports.jsx(SignIn$1.Button, { color: "primary", variant: "contained", type: "submit", fullWidth: true, disabled: isAuthLoading, onClick: () => {
44323
+ handleAuthenticate(authenticator.authenticatorId, {
44324
+ username,
44325
+ });
44326
+ setUsername('');
44327
+ }, children: t(keys.login.button) }), isAuthLoading && (jsxRuntimeExports.jsx("div", { className: "circular-progress-holder-authn", children: jsxRuntimeExports.jsx(ae, { className: "sign-in-button-progress" }) })), showSelfSignUp && (jsxRuntimeExports.jsxs(je, { container: true, children: [jsxRuntimeExports.jsx(SignIn$1.Typography, { children: t(keys.common.prefix.register) }), jsxRuntimeExports.jsx(SignIn$1.Link, { href: "./register", className: "asgardeo-register-link", children: t(keys.common.register) })] })), renderLoginOptions.length !== 0 && jsxRuntimeExports.jsxs(SignIn$1.Divider, { children: [" ", t(keys.common.or), " "] }), renderLoginOptions] }));
44328
+ };
44329
+
44291
44330
  /**
44292
44331
  * This component provides the sign-in functionality.
44293
44332
  *
@@ -44298,9 +44337,8 @@ n(css$1,{});
44298
44337
  * @returns {ReactElement} - React element.
44299
44338
  */
44300
44339
  const SignIn = (props) => {
44301
- var _a, _b, _c, _d, _e, _f, _g;
44340
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
44302
44341
  const { brandingProps, showFooter = true, showLogo = true, showSignUp } = props;
44303
- const [authResponse, setAuthResponse] = React$1.useState();
44304
44342
  const [isComponentLoading, setIsComponentLoading] = React$1.useState(true);
44305
44343
  const [alert, setAlert] = React$1.useState();
44306
44344
  const [showSelfSignUp, setShowSelfSignUp] = React$1.useState(showSignUp);
@@ -44325,7 +44363,7 @@ const SignIn = (props) => {
44325
44363
  */
44326
44364
  authorize()
44327
44365
  .then((response) => {
44328
- setAuthResponse(response);
44366
+ authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(response);
44329
44367
  setIsComponentLoading(false);
44330
44368
  })
44331
44369
  .catch((error) => {
@@ -44340,14 +44378,14 @@ const SignIn = (props) => {
44340
44378
  * @param {object} [authParams] - Authentication parameters.
44341
44379
  */
44342
44380
  const handleAuthenticate = (authenticatorId, authParams) => __awaiter$1(void 0, void 0, void 0, function* () {
44343
- var _h, _j, _k;
44381
+ var _k, _l, _m;
44344
44382
  setAlert(undefined);
44345
- if (authResponse === undefined) {
44383
+ if ((authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === undefined) {
44346
44384
  throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-IV02', 'Auth response is undefined.');
44347
44385
  }
44348
44386
  authContext.setIsAuthLoading(true);
44349
44387
  const resp = yield authenticate({
44350
- flowId: authResponse.flowId,
44388
+ flowId: authContext === null || authContext === void 0 ? void 0 : authContext.authResponse.flowId,
44351
44389
  selectedAuthenticator: {
44352
44390
  authenticatorId,
44353
44391
  params: authParams,
@@ -44358,12 +44396,12 @@ const SignIn = (props) => {
44358
44396
  throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-SE03', 'Authentication failed.', authnError.stack);
44359
44397
  });
44360
44398
  if (!authParams) {
44361
- const metaData = (_j = (_h = resp.nextStep) === null || _h === void 0 ? void 0 : _h.authenticators[0]) === null || _j === void 0 ? void 0 : _j.metadata;
44399
+ const metaData = (_l = (_k = resp.nextStep) === null || _k === void 0 ? void 0 : _k.authenticators[0]) === null || _l === void 0 ? void 0 : _l.metadata;
44362
44400
  if (metaData.promptType === PromptType.RedirectionPromt) {
44363
44401
  /**
44364
44402
  * Open a popup window to handle redirection prompts
44365
44403
  */
44366
- window.open((_k = metaData.additionalData) === null || _k === void 0 ? void 0 : _k.redirectUrl, resp.nextStep.authenticators[0].authenticator, 'width=500,height=600');
44404
+ window.open((_m = metaData.additionalData) === null || _m === void 0 ? void 0 : _m.redirectUrl, resp.nextStep.authenticators[0].authenticator, 'width=500,height=600');
44367
44405
  /**
44368
44406
  * Add an event listener to the window to capture the message from the popup
44369
44407
  */
@@ -44385,25 +44423,25 @@ const SignIn = (props) => {
44385
44423
  });
44386
44424
  }
44387
44425
  else if (metaData.promptType === PromptType.UserPrompt) {
44388
- setAuthResponse(resp);
44426
+ authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(resp);
44389
44427
  }
44390
44428
  }
44391
44429
  else if (resp.flowStatus === FlowStatus.SuccessCompleted && resp.authData) {
44392
44430
  /**
44393
44431
  * when the authentication is successful, generate the token
44394
44432
  */
44395
- setAuthResponse(resp);
44433
+ authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(resp);
44396
44434
  const authInstance = AuthClient.getInstance();
44397
44435
  const state = (yield authInstance.getDataLayer().getTemporaryDataParameter('state')).toString();
44398
44436
  yield authInstance.requestAccessToken(resp.authData.code, resp.authData.session_state, state);
44399
44437
  authContext.setAuthentication();
44400
44438
  }
44401
44439
  else if (resp.flowStatus === FlowStatus.FailIncomplete) {
44402
- setAuthResponse(Object.assign(Object.assign({}, resp), { nextStep: authResponse.nextStep }));
44440
+ authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(Object.assign(Object.assign({}, resp), { nextStep: authContext === null || authContext === void 0 ? void 0 : authContext.authResponse.nextStep }));
44403
44441
  setAlert({ alertType: { error: true }, key: keys.common.error });
44404
44442
  }
44405
44443
  else {
44406
- setAuthResponse(resp);
44444
+ authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(resp);
44407
44445
  setShowSelfSignUp(false);
44408
44446
  }
44409
44447
  authContext.setIsAuthLoading(false);
@@ -44417,13 +44455,17 @@ const SignIn = (props) => {
44417
44455
  return LoginOptions;
44418
44456
  };
44419
44457
  const renderSignIn = () => {
44420
- var _a;
44421
- const authenticators = (_a = authResponse === null || authResponse === void 0 ? void 0 : authResponse.nextStep) === null || _a === void 0 ? void 0 : _a.authenticators;
44458
+ var _a, _b;
44459
+ const authenticators = (_b = (_a = authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === null || _a === void 0 ? void 0 : _a.nextStep) === null || _b === void 0 ? void 0 : _b.authenticators;
44422
44460
  if (authenticators) {
44423
44461
  const usernamePasswordAuthenticator = authenticators.find((authenticator) => authenticator.authenticator === 'Username & Password');
44424
44462
  if (usernamePasswordAuthenticator) {
44425
44463
  return (jsxRuntimeExports.jsx(BasicAuth, { brandingProps: brandingProps, authenticator: usernamePasswordAuthenticator, handleAuthenticate: handleAuthenticate, showSelfSignUp: showSelfSignUp, alert: alert, renderLoginOptions: renderLoginOptions(authenticators.filter((auth) => auth.authenticatorId !== usernamePasswordAuthenticator.authenticatorId)) }));
44426
44464
  }
44465
+ const identifierFirstAuthenticator = authenticators.find((authenticator) => authenticator.authenticator === 'Identifier First');
44466
+ if (identifierFirstAuthenticator) {
44467
+ return (jsxRuntimeExports.jsx(IdentifierFirst, { brandingProps: brandingProps, authenticator: identifierFirstAuthenticator, handleAuthenticate: handleAuthenticate, showSelfSignUp: showSelfSignUp, alert: alert, renderLoginOptions: renderLoginOptions(authenticators.filter((auth) => auth.authenticatorId !== identifierFirstAuthenticator.authenticatorId)) }));
44468
+ }
44427
44469
  if (authenticators.length === 1) {
44428
44470
  if (authenticators[0].authenticator === 'TOTP') {
44429
44471
  return (jsxRuntimeExports.jsx(Totp, { brandingProps: brandingProps, authenticator: authenticators[0], alert: alert, handleAuthenticate: handleAuthenticate }));
@@ -44431,14 +44473,14 @@ const SignIn = (props) => {
44431
44473
  if (
44432
44474
  // TODO: change after api based auth gets fixed
44433
44475
  new SPACryptoUtils()
44434
- .base64URLDecode(authResponse.nextStep.authenticators[0].authenticatorId)
44476
+ .base64URLDecode(authContext === null || authContext === void 0 ? void 0 : authContext.authResponse.nextStep.authenticators[0].authenticatorId)
44435
44477
  .split(':')[0] === 'email-otp-authenticator') {
44436
44478
  return (jsxRuntimeExports.jsx(EmailOtp, { alert: alert, brandingProps: brandingProps, authenticator: authenticators[0], handleAuthenticate: handleAuthenticate }));
44437
44479
  }
44438
44480
  if (
44439
44481
  // TODO: change after api based auth gets fixed
44440
44482
  new SPACryptoUtils()
44441
- .base64URLDecode(authResponse.nextStep.authenticators[0].authenticatorId)
44483
+ .base64URLDecode(authContext === null || authContext === void 0 ? void 0 : authContext.authResponse.nextStep.authenticators[0].authenticatorId)
44442
44484
  .split(':')[0] === 'sms-otp-authenticator') {
44443
44485
  return (jsxRuntimeExports.jsx(SmsOtp, { alert: alert, brandingProps: brandingProps, authenticator: authenticators[0], handleAuthenticate: handleAuthenticate }));
44444
44486
  }
@@ -44464,15 +44506,15 @@ const SignIn = (props) => {
44464
44506
  if (showFooter && copyrightText.includes('{{currentYear}}')) {
44465
44507
  copyrightText = copyrightText.replace('{{currentYear}}', new Date().getFullYear().toString());
44466
44508
  }
44467
- return (jsxRuntimeExports.jsx(eo, { theme: generateThemeSignIn(componentBranding === null || componentBranding === void 0 ? void 0 : componentBranding.preference.theme), children: jsxRuntimeExports.jsxs(SignIn$1, { className: "Box-asgardeoSignIn", children: [showLogo && !(isLoading || isComponentLoading) && (jsxRuntimeExports.jsx(SignIn$1.Image, { className: "asgardeo-sign-in-logo", src: imgUrl })), (authResponse === null || authResponse === void 0 ? void 0 : authResponse.flowStatus) !== FlowStatus.SuccessCompleted && !isAuthenticated && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [renderSignIn(), showFooter && !(isLoading || isComponentLoading) && (jsxRuntimeExports.jsx(SignIn$1.Footer, { className: "asgardeo-sign-in-footer", copyrights: { children: copyrightText }, items: [
44509
+ return (jsxRuntimeExports.jsx(eo, { theme: generateThemeSignIn(componentBranding === null || componentBranding === void 0 ? void 0 : componentBranding.preference.theme), children: jsxRuntimeExports.jsxs(SignIn$1, { className: "Box-asgardeoSignIn", children: [showLogo && !(isLoading || isComponentLoading) && (jsxRuntimeExports.jsx(SignIn$1.Image, { className: "asgardeo-sign-in-logo", src: imgUrl })), ((_g = authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === null || _g === void 0 ? void 0 : _g.flowStatus) !== FlowStatus.SuccessCompleted && !isAuthenticated && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [renderSignIn(), showFooter && !(isLoading || isComponentLoading) && (jsxRuntimeExports.jsx(SignIn$1.Footer, { className: "asgardeo-sign-in-footer", copyrights: { children: copyrightText }, items: [
44468
44510
  {
44469
44511
  children: (jsxRuntimeExports.jsx(SignIn$1.Link, { href: componentBranding.preference.urls.privacyPolicyURL, children: t(keys.common.privacy.policy) })),
44470
44512
  },
44471
44513
  {
44472
44514
  children: (jsxRuntimeExports.jsx(SignIn$1.Link, { href: componentBranding.preference.urls.termsOfUseURL, children: t(keys.common.terms.of.service) })),
44473
44515
  },
44474
- { children: jsxRuntimeExports.jsx(SignIn$1.Typography, { children: (_g = componentBranding === null || componentBranding === void 0 ? void 0 : componentBranding.locale) !== null && _g !== void 0 ? _g : DEFAULT_LOCALE }) },
44475
- ] }))] })), ((authResponse === null || authResponse === void 0 ? void 0 : authResponse.flowStatus) === FlowStatus.SuccessCompleted || isAuthenticated) && (jsxRuntimeExports.jsx("div", { style: { backgroundColor: 'white', padding: '1rem' }, children: "Successfully Authenticated" }))] }) }));
44516
+ { children: jsxRuntimeExports.jsx(SignIn$1.Typography, { children: (_h = componentBranding === null || componentBranding === void 0 ? void 0 : componentBranding.locale) !== null && _h !== void 0 ? _h : DEFAULT_LOCALE }) },
44517
+ ] }))] })), (((_j = authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === null || _j === void 0 ? void 0 : _j.flowStatus) === FlowStatus.SuccessCompleted || isAuthenticated) && (jsxRuntimeExports.jsx("div", { style: { backgroundColor: 'white', padding: '1rem' }, children: "Successfully Authenticated" }))] }) }));
44476
44518
  };
44477
44519
 
44478
44520
  /**
@@ -44883,6 +44925,7 @@ const AsgardeoProvider = (props) => {
44883
44925
  const [isBrandingLoading, setIsBrandingLoading] = React$1.useState(true);
44884
44926
  const [isTextLoading, setIsTextLoading] = React$1.useState(true);
44885
44927
  const [isAuthLoading, setIsAuthLoading] = React$1.useState(false);
44928
+ const [authResponse, setAuthResponse] = React$1.useState();
44886
44929
  const onSignInRef = React$1.useRef();
44887
44930
  const onSignOutRef = React$1.useRef();
44888
44931
  const setOnSignIn = React$1.useCallback((newOnSignIn) => {
@@ -44933,6 +44976,7 @@ const AsgardeoProvider = (props) => {
44933
44976
  }, [config.signInRedirectURL, setAuthentication]);
44934
44977
  const value = React$1.useMemo(() => ({
44935
44978
  accessToken,
44979
+ authResponse,
44936
44980
  config,
44937
44981
  isAuthLoading,
44938
44982
  isAuthenticated,
@@ -44940,6 +44984,7 @@ const AsgardeoProvider = (props) => {
44940
44984
  isGlobalLoading: isBrandingLoading || isTextLoading || isAuthLoading,
44941
44985
  isTextLoading,
44942
44986
  onSignOutRef,
44987
+ setAuthResponse,
44943
44988
  setAuthentication,
44944
44989
  setIsAuthLoading,
44945
44990
  setIsBrandingLoading,
@@ -44949,11 +44994,13 @@ const AsgardeoProvider = (props) => {
44949
44994
  user,
44950
44995
  }), [
44951
44996
  accessToken,
44997
+ authResponse,
44952
44998
  config,
44953
44999
  isAuthLoading,
44954
45000
  isAuthenticated,
44955
45001
  isBrandingLoading,
44956
45002
  isTextLoading,
45003
+ setAuthResponse,
44957
45004
  setAuthentication,
44958
45005
  setOnSignIn,
44959
45006
  setOnSignOut,