@oneblink/apps-react 10.3.1-beta.6 → 11.0.0-beta.1

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.
Files changed (49) hide show
  1. package/dist/apps/auth-service.d.ts +3 -2
  2. package/dist/apps/auth-service.js +2 -2
  3. package/dist/apps/auth-service.js.map +1 -1
  4. package/dist/apps/services/AWSCognitoClient.d.ts +39 -4
  5. package/dist/apps/services/AWSCognitoClient.js +238 -23
  6. package/dist/apps/services/AWSCognitoClient.js.map +1 -1
  7. package/dist/apps/services/cognito.d.ts +50 -41
  8. package/dist/apps/services/cognito.js +85 -48
  9. package/dist/apps/services/cognito.js.map +1 -1
  10. package/dist/components/mfa/MfaAuthenticatorAppDialog.d.ts +12 -0
  11. package/dist/components/mfa/MfaAuthenticatorAppDialog.js +64 -0
  12. package/dist/components/mfa/MfaAuthenticatorAppDialog.js.map +1 -0
  13. package/dist/components/mfa/MfaDisableDialog.d.ts +10 -0
  14. package/dist/components/mfa/MfaDisableDialog.js +31 -0
  15. package/dist/components/mfa/MfaDisableDialog.js.map +1 -0
  16. package/dist/components/mfa/MfaErrorSnackbar.d.ts +10 -0
  17. package/dist/components/mfa/MfaErrorSnackbar.js +17 -0
  18. package/dist/components/mfa/MfaErrorSnackbar.js.map +1 -0
  19. package/dist/components/mfa/MfaMethodRow.d.ts +19 -0
  20. package/dist/components/mfa/MfaMethodRow.js +10 -0
  21. package/dist/components/mfa/MfaMethodRow.js.map +1 -0
  22. package/dist/components/mfa/MfaPhoneNumberDialog.d.ts +11 -0
  23. package/dist/components/mfa/MfaPhoneNumberDialog.js +120 -0
  24. package/dist/components/mfa/MfaPhoneNumberDialog.js.map +1 -0
  25. package/dist/components/mfa/MfaRemovePhoneNumberDialog.d.ts +10 -0
  26. package/dist/components/mfa/MfaRemovePhoneNumberDialog.js +24 -0
  27. package/dist/components/mfa/MfaRemovePhoneNumberDialog.js.map +1 -0
  28. package/dist/components/mfa/MfaStatusChip.d.ts +10 -0
  29. package/dist/components/mfa/MfaStatusChip.js +29 -0
  30. package/dist/components/mfa/MfaStatusChip.js.map +1 -0
  31. package/dist/components/mfa/MfaSuccessSnackbar.d.ts +10 -0
  32. package/dist/components/mfa/MfaSuccessSnackbar.js +17 -0
  33. package/dist/components/mfa/MfaSuccessSnackbar.js.map +1 -0
  34. package/dist/components/mfa/MultiFactorAuthentication.d.ts +1 -2
  35. package/dist/components/mfa/MultiFactorAuthentication.js +30 -30
  36. package/dist/components/mfa/MultiFactorAuthentication.js.map +1 -1
  37. package/dist/hooks/useLogin.d.ts +14 -8
  38. package/dist/hooks/useLogin.js +16 -6
  39. package/dist/hooks/useLogin.js.map +1 -1
  40. package/dist/hooks/useMfa.d.ts +46 -14
  41. package/dist/hooks/useMfa.js +388 -43
  42. package/dist/hooks/useMfa.js.map +1 -1
  43. package/dist/index.d.ts +7 -0
  44. package/dist/index.js +7 -0
  45. package/dist/index.js.map +1 -1
  46. package/package.json +2 -2
  47. package/dist/components/mfa/MfaDialog.d.ts +0 -9
  48. package/dist/components/mfa/MfaDialog.js +0 -47
  49. package/dist/components/mfa/MfaDialog.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/apps/services/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,gBAA0C,MAAM,oBAAoB,CAAA;AAE3E,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAa,WAAW,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAU1D,MAAM,WAAW,GAAG,YAAY,CAAA;AAEhC,IAAI,gBAAgB,GAA4B,IAAI,CAAA;AAEpD,SAAS,IAAI,CAAC,kBAAsC;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,qBAAqB,CAAC,UAAU,WAAW,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAA;AACpK,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,KAAK,UAAU,iBAAiB;IAC9B,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,8HAA8H,CAC/H,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAA;AACnD,CAAC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,2GAA2G,CAC5G,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,UAAU,EAAE,CAAA;AAC5C,CAAC;AACD;;;;;;;;;;;;;;;;GAgBG;AACH,KAAK,UAAU,QAAQ;IACrB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAA;AAC1C,CAAC;AAED,OAAO,EACL,IAAI,EACJ,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EAEnB,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,oBAAoB,GACrB,CAAA","sourcesContent":["import { jwtDecode } from 'jwt-decode'\n\nimport AWSCognitoClient, { LoginAttemptResponse } from './AWSCognitoClient'\n\nimport * as offlineService from '../offline-service'\nimport { userService } from '@oneblink/sdk-core'\nimport { MiscTypes } from '@oneblink/types'\nimport { HTTPError, postRequest } from './fetch'\nimport tenants from '../tenants'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\n\ninterface CognitoServiceData {\n oAuthClientId: string\n loginDomain: string\n region: string\n redirectUri: string\n logoutUri: string\n}\n\nconst CONTINUE_TO = 'continueTo'\n\nlet awsCognitoClient: null | AWSCognitoClient = null\n\nfunction init(cognitoServiceData: CognitoServiceData) {\n console.log('Initiating CognitoIdentityServiceProvider', cognitoServiceData)\n\n awsCognitoClient = new AWSCognitoClient({\n clientId: cognitoServiceData.oAuthClientId,\n region: cognitoServiceData.region,\n loginDomain: cognitoServiceData.loginDomain,\n redirectUri: cognitoServiceData.redirectUri,\n logoutUri: cognitoServiceData.logoutUri,\n })\n}\n\n/**\n * Register a listener function that will be call when authentication tokens are\n * updated or removed.\n *\n * #### Example\n *\n * ```js\n * const listener = async () => {\n * // Check if the user is logged in still\n * const isLoggedIn = authService.isLoggedIn()\n * }\n * const deregister = await authService.registerAuthListener(listener)\n *\n * // When no longer needed, remember to deregister the listener\n * deregister()\n * ```\n *\n * @param listener\n * @returns\n */\nfunction registerAuthListener(listener: () => unknown): () => void {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to register a listener.',\n )\n }\n return awsCognitoClient.registerListener(listener)\n}\n\n/**\n * Create a session for a user by entering a username and password. If the user\n * requires a password reset, the \"resetPasswordCallback\" property will be\n * returned. This function should be called with the new password once entered\n * by the user. If the user requires an MFA token, the \"mfaCodeCallback\"\n * property will be returned. This function should be called with a one-time\n * token generated from an authenticator app. The functions returned are\n * recursive and the result from each of them is the same result from the\n * loginUsernamePassword() function. Each time the response includes a callback,\n * you will need to begin the process again until all callbacks are handled.\n *\n * #### Example\n *\n * ```js\n * async function handleLoginAttemptResponse({\n * resetPasswordCallback,\n * mfaCodeCallback,\n * }) {\n * // \"resetPasswordCallback\" will be undefined if a password reset was not required.\n * if (resetPasswordCallback) {\n * // Prompt the user to enter a new password\n * const newPassword = prompt(\n * 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.',\n * )\n * const resetPasswordResponse =\n * await resetPasswordCallback(newPassword)\n * return await handleLoginAttemptResponse(resetPasswordResponse)\n * }\n *\n * // \"mfaCodeCallback\" will be undefined if MFA is not setup.\n * if (mfaCodeCallback) {\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * 'Please enter a one-time code from your MFA app.',\n * )\n * const mfaCodeResponse = await mfaCodeCallback(code)\n * return await handleLoginAttemptResponse(mfaCodeResponse)\n * }\n * }\n *\n * const username = 'user@email.io'\n * const password = 'P@$5w0rd'\n *\n * const loginAttemptResponse = await authService.loginUsernamePassword(\n * username,\n * password,\n * )\n *\n * await handleLoginAttemptResponse(loginAttemptResponse)\n * ```\n *\n * @param username\n * @param password\n * @returns\n */\nasync function loginUsernamePassword(username: string, password: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n console.log('Attempting sign using username', username)\n return awsCognitoClient.loginUsernamePassword(\n username.toLowerCase(),\n password,\n )\n}\n\n/**\n * Redirect the user to the login screen. Passing an `identityProvider` is\n * optionally, it will allow users to skip the login page and be directed\n * straight to that providers login page\n *\n * #### Example\n *\n * ```js\n * // OPtionally pass a\n * const identityProvider = 'Google'\n * await authService.loginHostedUI(identityProvider)\n * // User will be redirected to login page or promise will resolve\n * ```\n *\n * @param identityProviderName\n * @returns\n */\nasync function loginHostedUI(identityProviderName?: string): Promise<void> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n const continueTo = `${window.location.pathname}${window.location.search}`\n localStorage.setItem(CONTINUE_TO, continueTo)\n\n return awsCognitoClient.loginHostedUI(identityProviderName)\n}\n\n/**\n * This function should be called when the user is redirected back to your app\n * after a login attempt. It will use the query string add the redirect URL to\n * create a session for the current user. It will return a URL as a `string`\n * that should be redirected to within your app.\n *\n * #### Example\n *\n * ```js\n * try {\n * const continueTo = await authService.handleAuthentication()\n * // Redirect the user back to where they were before attempting to login\n * window.location.href = continueTo\n * } catch (error) {\n * // handle failed login attempts here.\n * }\n * ```\n *\n * @returns\n */\nasync function handleAuthentication(): Promise<string> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to handle authentication in URL.',\n )\n }\n\n const continueTo = localStorage.getItem(CONTINUE_TO) || '/'\n if (isLoggedIn()) {\n console.log('Already authenticated, redirecting to:', continueTo)\n } else {\n await awsCognitoClient.handleAuthentication()\n }\n\n localStorage.removeItem(CONTINUE_TO)\n\n return continueTo\n}\n\n/**\n * Allow the currently logged in user to change their password by passing their\n * existing password and a new password.\n *\n * #### Example\n *\n * ```js\n * const currentPassword = 'P@$5w0rd'\n * const newPassword = 'P@$5w0rD'\n * await authService.changePassword(currentPassword, newPassword)\n * ```\n *\n * @param existingPassword\n * @param newPassword\n * @returns\n */\nasync function changePassword(existingPassword: string, newPassword: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to change passwords.',\n )\n }\n\n return await awsCognitoClient.changePassword(existingPassword, newPassword)\n}\n\n/**\n * Allow a user to start the forgot password process. The user will be emailed a\n * temporary code that must be passed with a new password to the function\n * returned.\n *\n * #### Example\n *\n * ```js\n * const username = 'user@email.io'\n * const finishForgotPassword = await authService.forgotPassword(username)\n *\n * // Prompt the user to enter the code and a new password\n * const code = prompt(\n * 'You have been emailed a verification code, please enter it here.',\n * )\n * const newPassword = prompt('Please enter a new password to continue.')\n * await finishForgotPassword(code, newPassword)\n * ```\n *\n * @param username\n * @param formsAppId Used to give the resulting email sent to the user\n * associated forms app branding and sending address\n * @returns\n */\nasync function forgotPassword(\n username: string,\n /**\n * Used to give the resulting email sent to the user associated forms app\n * branding and sending address\n */\n formsAppId?: number,\n): Promise<(code: string, password: string) => Promise<void>> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before starting the forgot password process.',\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/authentication/reset-password`\n await postRequest(url, {\n username,\n formsAppId,\n })\n } catch (err) {\n const error = err as HTTPError\n switch (error.status) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n\n return async (code, password) => {\n await awsCognitoClient?.confirmForgotPassword({\n username,\n code,\n password,\n })\n }\n}\n\n/**\n * Redirect the user to the logout screen to clear the users session on the\n * hosted login page. User will then be redirected to `/logout`. After being\n * redirected back to the application, the `logout()` function should be called\n * to clear the session data from browser storage.\n *\n * #### Example\n *\n * ```js\n * authService.logoutHostedUI()\n * ```\n */\nfunction logoutHostedUI(): void {\n if (awsCognitoClient) {\n awsCognitoClient.logoutHostedUI()\n }\n}\n\nasync function logout() {\n if (awsCognitoClient) {\n await awsCognitoClient.logout()\n }\n}\n\n/**\n * Check if the user is currently logged in\n *\n * #### Example\n *\n * ```js\n * const isLoggedIn = authService.isLoggedIn()\n * // handle user being logged in or not\n * ```\n *\n * @returns\n */\nfunction isLoggedIn(): boolean {\n return !!(awsCognitoClient && awsCognitoClient._getRefreshToken())\n}\n\nasync function getCognitoIdToken(): Promise<string | undefined> {\n if (!awsCognitoClient) {\n return\n }\n\n if (offlineService.isOffline()) {\n return awsCognitoClient._getIdToken()\n }\n\n return await awsCognitoClient.getIdToken()\n}\n\n/**\n * Get current users profile based on there Id Token payload. This will return\n * `null` if the the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const profile = authService.getUserProfile()\n * if (profile) {\n * // Use profile here\n * }\n * ```\n *\n * @returns\n */\nfunction getUserProfile(): MiscTypes.UserProfile | null {\n if (!awsCognitoClient) {\n return null\n }\n const idToken = awsCognitoClient._getIdToken()\n if (!idToken) {\n return null\n }\n\n const jwtToken = jwtDecode(idToken)\n return userService.parseUserProfile(jwtToken) || null\n}\n\nexport function getUsername(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return undefined\n }\n\n return profile.username\n}\n\n/**\n * A friendly `string` that represents the current user. Uses first name, last\n * name, full name and username. This will return `null` the current user is not\n * logged in.\n *\n * #### Example\n *\n * ```js\n * const name = authService.getUserFriendlyName()\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @returns\n */\nfunction getUserFriendlyName(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return\n }\n\n return userService.getUserFriendlyName(profile)\n}\n\n/**\n * Generate a QR code link to display to a user after they have initiated MFA\n * setup.\n *\n * #### Example\n *\n * ```js\n * const mfaSetupQrCodeUrl = authService.generateMfaQrCodeUrl()\n * if (mfaSetupQrCodeUrl) {\n * // use mfaSetupQrCodeUrl to display QR code to user\n * }\n * ```\n *\n * @returns\n */\nfunction generateMfaQrCodeUrl(\n mfaSetupConfiguration: Awaited<ReturnType<typeof setupMfa>>,\n): string | undefined {\n const profile = getUserProfile()\n if (!profile || !mfaSetupConfiguration) {\n return\n }\n\n return `otpauth://totp/${tenants.current.productShortName}:${profile.email}?secret=${mfaSetupConfiguration.secretCode}&issuer=${tenants.current.productShortName}`\n}\n\n/**\n * Check if MFA is enabled for this current user.\n *\n * #### Example\n *\n * ```js\n * const isMfaEnabled = await authService.checkIsMfaEnabled()\n * if (isMfaEnabled) {\n * // Allow disabling MFA\n * } else {\n * // Allow enabling MFA\n * }\n * ```\n *\n * @returns\n */\nasync function checkIsMfaEnabled() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking if the current user has MFA enabled.',\n )\n }\n\n return await awsCognitoClient.checkIsMfaEnabled()\n}\n\n/**\n * Disable MFA for the current user.\n *\n * #### Example\n *\n * ```js\n * await authService.disableMfa()\n * ```\n *\n * @returns\n */\nasync function disableMfa() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to disable MFA.',\n )\n }\n\n return await awsCognitoClient.disableMfa()\n}\n/**\n * Setup MFA for the current user. The result will include a callback that\n * should be called with the valid TOTP from an authenticator app.\n *\n * #### Example\n *\n * ```js\n * const { secretCode, mfaCodeCallback } = await authService.setupMfa()\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,\n * )\n * await mfaCodeCallback(code)\n * ```\n *\n * @returns\n */\nasync function setupMfa() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup MFA.',\n )\n }\n\n return await awsCognitoClient.setupMfa()\n}\n\nexport {\n init,\n registerAuthListener,\n loginUsernamePassword,\n loginHostedUI,\n handleAuthentication,\n changePassword,\n forgotPassword,\n logoutHostedUI,\n logout,\n isLoggedIn,\n getCognitoIdToken,\n getUserProfile,\n getUserFriendlyName,\n LoginAttemptResponse,\n checkIsMfaEnabled,\n disableMfa,\n setupMfa,\n generateMfaQrCodeUrl,\n}\n"]}
1
+ {"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/apps/services/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,gBAAgB,EAAE,EACvB,oBAAoB,GAKrB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAa,WAAW,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAU1D,MAAM,WAAW,GAAG,YAAY,CAAA;AAEhC,IAAI,gBAAgB,GAA4B,IAAI,CAAA;AAEpD,SAAS,IAAI,CAAC,kBAAsC;IAClD,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,kBAAkB,CAAC,CAAA;IAE5E,gBAAgB,GAAG,IAAI,gBAAgB,CAAC;QACtC,QAAQ,EAAE,kBAAkB,CAAC,aAAa;QAC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\n\nimport AWSCognitoClient, {\n DEFAULT_MFA_SETTINGS,\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n} from './AWSCognitoClient'\n\nimport * as offlineService from '../offline-service'\nimport { userService } from '@oneblink/sdk-core'\nimport { MiscTypes } from '@oneblink/types'\nimport { HTTPError, postRequest } from './fetch'\nimport tenants from '../tenants'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\n\ninterface CognitoServiceData {\n oAuthClientId: string\n loginDomain: string\n region: string\n redirectUri: string\n logoutUri: string\n}\n\nconst CONTINUE_TO = 'continueTo'\n\nlet awsCognitoClient: null | AWSCognitoClient = null\n\nfunction init(cognitoServiceData: CognitoServiceData) {\n console.log('Initiating CognitoIdentityServiceProvider', cognitoServiceData)\n\n awsCognitoClient = new AWSCognitoClient({\n clientId: cognitoServiceData.oAuthClientId,\n region: cognitoServiceData.region,\n loginDomain: cognitoServiceData.loginDomain,\n redirectUri: cognitoServiceData.redirectUri,\n logoutUri: cognitoServiceData.logoutUri,\n })\n}\n\n/**\n * Register a listener function that will be call when authentication tokens are\n * updated or removed.\n *\n * #### Example\n *\n * ```js\n * const listener = async () => {\n * // Check if the user is logged in still\n * const isLoggedIn = authService.isLoggedIn()\n * }\n * const deregister = await authService.registerAuthListener(listener)\n *\n * // When no longer needed, remember to deregister the listener\n * deregister()\n * ```\n *\n * @param listener\n * @returns\n */\nfunction registerAuthListener(listener: () => unknown): () => void {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to register a listener.',\n )\n }\n return awsCognitoClient.registerListener(listener)\n}\n\n/**\n * Create a session for a user by entering a username and password. If the user\n * requires a password reset, the \"resetPasswordCallback\" property will be\n * returned. This function should be called with the new password once entered\n * by the user. If the user requires an MFA token, the \"mfa\" property will be\n * returned. Its \"codeCallback\" should be called with the one-time token. The\n * functions returned are recursive and the result from each of them is the same\n * result from the loginUsernamePassword() function. Each time the response\n * includes a callback, you will need to begin the process again until all\n * callbacks are handled.\n *\n * #### Example\n *\n * ```js\n * async function handleLoginAttemptResponse({\n * resetPasswordCallback,\n * mfa,\n * }) {\n * // \"resetPasswordCallback\" will be undefined if a password reset was not required.\n * if (resetPasswordCallback) {\n * // Prompt the user to enter a new password\n * const newPassword = prompt(\n * 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.',\n * )\n * const resetPasswordResponse =\n * await resetPasswordCallback(newPassword)\n * return await handleLoginAttemptResponse(resetPasswordResponse)\n * }\n *\n * // \"mfa\" will be undefined if MFA is not setup.\n * if (mfa) {\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * mfa.method === 'email'\n * ? 'Please enter the one-time code sent to your email.'\n * : 'Please enter a one-time code from your MFA app.',\n * )\n * const mfaCodeResponse = await mfa.codeCallback(code)\n * return await handleLoginAttemptResponse(mfaCodeResponse)\n * }\n * }\n *\n * const username = 'user@email.io'\n * const password = 'P@$5w0rd'\n *\n * const loginAttemptResponse = await authService.loginUsernamePassword(\n * username,\n * password,\n * )\n *\n * await handleLoginAttemptResponse(loginAttemptResponse)\n * ```\n *\n * @param username\n * @param password\n * @returns\n */\nasync function loginUsernamePassword(username: string, password: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n console.log('Attempting sign using username', username)\n return awsCognitoClient.loginUsernamePassword(\n username.toLowerCase(),\n password,\n )\n}\n\n/**\n * Redirect the user to the login screen. Passing an `identityProvider` is\n * optionally, it will allow users to skip the login page and be directed\n * straight to that providers login page\n *\n * #### Example\n *\n * ```js\n * // OPtionally pass a\n * const identityProvider = 'Google'\n * await authService.loginHostedUI(identityProvider)\n * // User will be redirected to login page or promise will resolve\n * ```\n *\n * @param identityProviderName\n * @returns\n */\nasync function loginHostedUI(identityProviderName?: string): Promise<void> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n const continueTo = `${window.location.pathname}${window.location.search}`\n localStorage.setItem(CONTINUE_TO, continueTo)\n\n return awsCognitoClient.loginHostedUI(identityProviderName)\n}\n\n/**\n * This function should be called when the user is redirected back to your app\n * after a login attempt. It will use the query string add the redirect URL to\n * create a session for the current user. It will return a URL as a `string`\n * that should be redirected to within your app.\n *\n * #### Example\n *\n * ```js\n * try {\n * const continueTo = await authService.handleAuthentication()\n * // Redirect the user back to where they were before attempting to login\n * window.location.href = continueTo\n * } catch (error) {\n * // handle failed login attempts here.\n * }\n * ```\n *\n * @returns\n */\nasync function handleAuthentication(): Promise<string> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to handle authentication in URL.',\n )\n }\n\n const continueTo = localStorage.getItem(CONTINUE_TO) || '/'\n if (isLoggedIn()) {\n console.log('Already authenticated, redirecting to:', continueTo)\n } else {\n await awsCognitoClient.handleAuthentication()\n }\n\n localStorage.removeItem(CONTINUE_TO)\n\n return continueTo\n}\n\n/**\n * Allow the currently logged in user to change their password by passing their\n * existing password and a new password.\n *\n * #### Example\n *\n * ```js\n * const currentPassword = 'P@$5w0rd'\n * const newPassword = 'P@$5w0rD'\n * await authService.changePassword(currentPassword, newPassword)\n * ```\n *\n * @param existingPassword\n * @param newPassword\n * @returns\n */\nasync function changePassword(existingPassword: string, newPassword: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to change passwords.',\n )\n }\n\n return await awsCognitoClient.changePassword(existingPassword, newPassword)\n}\n\n/**\n * Allow a user to start the forgot password process. The user will be emailed a\n * temporary code that must be passed with a new password to the function\n * returned.\n *\n * #### Example\n *\n * ```js\n * const username = 'user@email.io'\n * const finishForgotPassword = await authService.forgotPassword(username)\n *\n * // Prompt the user to enter the code and a new password\n * const code = prompt(\n * 'You have been emailed a verification code, please enter it here.',\n * )\n * const newPassword = prompt('Please enter a new password to continue.')\n * await finishForgotPassword(code, newPassword)\n * ```\n *\n * @param username\n * @param formsAppId Used to give the resulting email sent to the user\n * associated forms app branding and sending address\n * @returns\n */\nasync function forgotPassword(\n username: string,\n /**\n * Used to give the resulting email sent to the user associated forms app\n * branding and sending address\n */\n formsAppId?: number,\n): Promise<(code: string, password: string) => Promise<void>> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before starting the forgot password process.',\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/authentication/reset-password`\n await postRequest(url, {\n username,\n formsAppId,\n })\n } catch (err) {\n const error = err as HTTPError\n switch (error.status) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n\n return async (code, password) => {\n await awsCognitoClient?.confirmForgotPassword({\n username,\n code,\n password,\n })\n }\n}\n\n/**\n * Redirect the user to the logout screen to clear the users session on the\n * hosted login page. User will then be redirected to `/logout`. After being\n * redirected back to the application, the `logout()` function should be called\n * to clear the session data from browser storage.\n *\n * #### Example\n *\n * ```js\n * authService.logoutHostedUI()\n * ```\n */\nfunction logoutHostedUI(): void {\n if (awsCognitoClient) {\n awsCognitoClient.logoutHostedUI()\n }\n}\n\nasync function logout() {\n if (awsCognitoClient) {\n await awsCognitoClient.logout()\n }\n}\n\n/**\n * Check if the user is currently logged in\n *\n * #### Example\n *\n * ```js\n * const isLoggedIn = authService.isLoggedIn()\n * // handle user being logged in or not\n * ```\n *\n * @returns\n */\nfunction isLoggedIn(): boolean {\n return !!(awsCognitoClient && awsCognitoClient._getRefreshToken())\n}\n\nasync function getCognitoIdToken(): Promise<string | undefined> {\n if (!awsCognitoClient) {\n return\n }\n\n if (offlineService.isOffline()) {\n return awsCognitoClient._getIdToken()\n }\n\n return await awsCognitoClient.getIdToken()\n}\n\n/**\n * Get current users profile based on there Id Token payload. This will return\n * `null` if the the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const profile = authService.getUserProfile()\n * if (profile) {\n * // Use profile here\n * }\n * ```\n *\n * @returns\n */\nfunction getUserProfile(): MiscTypes.UserProfile | null {\n if (!awsCognitoClient) {\n return null\n }\n const idToken = awsCognitoClient._getIdToken()\n if (!idToken) {\n return null\n }\n\n const jwtToken = jwtDecode(idToken)\n return userService.parseUserProfile(jwtToken) || null\n}\n\nexport function getUsername(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return undefined\n }\n\n return profile.username\n}\n\n/**\n * A friendly `string` that represents the current user. Uses first name, last\n * name, full name and username. This will return `null` the current user is not\n * logged in.\n *\n * #### Example\n *\n * ```js\n * const name = authService.getUserFriendlyName()\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @returns\n */\nfunction getUserFriendlyName(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return\n }\n\n return userService.getUserFriendlyName(profile)\n}\n\n/**\n * Generate a QR code link to display to a user after they have initiated\n * authenticator app MFA setup.\n *\n * #### Example\n *\n * ```js\n * const mfaAuthenticatorAppSetupQrCodeUrl =\n * authService.generateMfaAuthenticatorAppQrCodeUrl()\n * if (mfaAuthenticatorAppSetupQrCodeUrl) {\n * // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user\n * }\n * ```\n *\n * @returns\n */\nfunction generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup: Awaited<\n ReturnType<typeof setupMfaAuthenticatorApp>\n >,\n): string | undefined {\n const profile = getUserProfile()\n if (!profile || !mfaAuthenticatorAppSetup) {\n return\n }\n\n return `otpauth://totp/${tenants.current.productShortName}:${profile.email}?secret=${mfaAuthenticatorAppSetup.secretCode}&issuer=${tenants.current.productShortName}`\n}\n\n/**\n * Check if the current user meets an MFA requirement.\n *\n * #### Example\n *\n * ```js\n * const { mfaSettings, userMeetsMfaRequirement } =\n * await authService.checkIsMfaEnabled('any')\n * if (userMeetsMfaRequirement) {\n * // User has met the MFA requirement\n * } else {\n * // Prompt user to set up MFA\n * }\n * ```\n *\n * @returns\n */\nasync function checkIsMfaEnabled(\n mfaRequirement: MiscTypes.MfaRequirement | undefined,\n): Promise<MfaRequirementCheckResult> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking if the current user has MFA enabled.',\n )\n }\n\n return await awsCognitoClient.checkIsMfaEnabled(mfaRequirement)\n}\n\nasync function getMfaSettings(abortSignal?: AbortSignal) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking MFA settings.',\n )\n }\n\n return await awsCognitoClient.getMfaSettings(abortSignal)\n}\n\nasync function updateUserPhoneNumber(phoneNumber: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before updating the user phone number.',\n )\n }\n\n return await awsCognitoClient.updateUserPhoneNumber(phoneNumber)\n}\n\nasync function removeUserPhoneNumber() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before removing the user phone number.',\n )\n }\n\n return await awsCognitoClient.removeUserPhoneNumber()\n}\n\nasync function sendPhoneNumberVerificationCode() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before sending a phone number verification code.',\n )\n }\n\n return await awsCognitoClient.sendPhoneNumberVerificationCode()\n}\n\nasync function verifyUserPhoneNumber(code: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before verifying the user phone number.',\n )\n }\n\n return await awsCognitoClient.verifyUserPhoneNumber(code)\n}\n\nasync function setupSmsMfa(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup SMS MFA.',\n )\n }\n\n return await awsCognitoClient.setupSmsMfa(options)\n}\n\nasync function disableMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to disable an MFA method.',\n )\n }\n\n return await awsCognitoClient.disableMfaMethod(method)\n}\n\nasync function setPreferredMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to set the preferred MFA method.',\n )\n }\n\n return await awsCognitoClient.setPreferredMfaMethod(method)\n}\n\n/**\n * Setup authenticator app MFA for the current user. The result will include a\n * callback that should be called with the valid TOTP from an authenticator\n * app.\n *\n * #### Example\n *\n * ```js\n * const { secretCode, mfaCodeCallback } =\n * await authService.setupMfaAuthenticatorApp()\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,\n * )\n * await mfaCodeCallback(code)\n * ```\n *\n * @returns\n */\nasync function setupMfaAuthenticatorApp(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup authenticator app MFA.',\n )\n }\n\n return await awsCognitoClient.setupMfaAuthenticatorApp(options)\n}\n\nexport {\n init,\n registerAuthListener,\n loginUsernamePassword,\n loginHostedUI,\n handleAuthentication,\n changePassword,\n forgotPassword,\n logoutHostedUI,\n logout,\n isLoggedIn,\n getCognitoIdToken,\n getUserProfile,\n getUserFriendlyName,\n checkIsMfaEnabled,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n sendPhoneNumberVerificationCode,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupSmsMfa,\n setupMfaAuthenticatorApp,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n}\nexport type {\n LoginAttemptResponse,\n MfaMethod,\n MfaRequirementCheckResult,\n MfaSettings,\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ declare function MfaAuthenticatorAppDialog(): import("react/jsx-runtime").JSX.Element;
3
+ /**
4
+ * React Component that guides users through authenticator app MFA setup,
5
+ * including QR code scanning and verification code entry. Typically rendered by
6
+ * `<MultiFactorAuthentication />` within an
7
+ * `<MfaProvider />` tree.
8
+ *
9
+ * @returns
10
+ */
11
+ declare const _default: React.MemoExoticComponent<typeof MfaAuthenticatorAppDialog>;
12
+ export default _default;
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { QRCodeSVG } from 'qrcode.react';
4
+ import { Box, Collapse, Dialog, Grid, Link, Typography, DialogContent, DialogActions, Button, DialogTitle, } from '@mui/material';
5
+ import { authService } from '../../apps';
6
+ import useBooleanState from '../../hooks/useBooleanState';
7
+ import useMfa from '../../hooks/useMfa';
8
+ import { CopyToClipBoardIconButton } from '../CopyToClipboardIconButton';
9
+ import InputField from '../InputField';
10
+ function MfaAuthenticatorAppDialog() {
11
+ const { mfaAuthenticatorAppSetup, cancelMfaAuthenticatorAppSetup, completeMfaAuthenticatorAppSetup, } = useMfa();
12
+ const [code, setState] = React.useState('');
13
+ const [isShowingSecretCode, showSecretCode, hideSecretCode] = useBooleanState(false);
14
+ const qrcodeValue = React.useMemo(() => {
15
+ if (mfaAuthenticatorAppSetup) {
16
+ return authService.generateMfaAuthenticatorAppQrCodeUrl(mfaAuthenticatorAppSetup);
17
+ }
18
+ }, [mfaAuthenticatorAppSetup]);
19
+ const [isSaving, startSaving, stopSaving] = useBooleanState(false);
20
+ const handleSubmit = React.useCallback(async (event) => {
21
+ event.preventDefault();
22
+ if (!code || !mfaAuthenticatorAppSetup || isSaving) {
23
+ return;
24
+ }
25
+ startSaving();
26
+ try {
27
+ await mfaAuthenticatorAppSetup.mfaCodeCallback(code);
28
+ await completeMfaAuthenticatorAppSetup();
29
+ }
30
+ finally {
31
+ stopSaving();
32
+ }
33
+ }, [
34
+ code,
35
+ completeMfaAuthenticatorAppSetup,
36
+ isSaving,
37
+ mfaAuthenticatorAppSetup,
38
+ startSaving,
39
+ stopSaving,
40
+ ]);
41
+ return (_jsx(React.Fragment, { children: _jsx(Dialog, { open: !!mfaAuthenticatorAppSetup, onClose: cancelMfaAuthenticatorAppSetup, title: "Complete MFA Setup", children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(DialogTitle, { children: "Authenticator App Setup" }), _jsxs(DialogContent, { dividers: true, children: [_jsxs(Typography, { variant: "body2", component: "p", sx: { mb: 2 }, children: ["Authenticator apps like", ' ', _jsx(Link, { href: "https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2", target: "_blank", rel: "noopener noreferrer", children: "Google Authenticator" }), ' ', "and", ' ', _jsx(Link, { href: "https://www.microsoft.com/en-us/security/mobile-authenticator-app", target: "_blank", rel: "noopener noreferrer", children: "Microsoft Authenticator" }), ' ', "generate one-time passwords that are used as a second factor to verify your identity when prompted during sign-in."] }), _jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: "Scan the QR code" }), _jsx(Typography, { variant: "body2", sx: { mb: 2 }, children: "Use an authenticator app or browser extension to scan the QR code below." }), _jsx(Box, { marginBottom: 2, children: _jsxs(Grid, { container: true, spacing: 2, alignItems: "center", children: [_jsx(Grid, { children: _jsx(Box, { border: 1, padding: 2, borderRadius: 1, borderColor: "divider", display: "inline-block", lineHeight: 0, children: _jsx(QRCodeSVG, { value: qrcodeValue || '' }) }) }), _jsx(Grid, { size: { xs: 'grow' }, children: _jsxs(Typography, { variant: "caption", color: "text.secondary", children: ["Having trouble scanning the QR code?", ' ', _jsx(Link, { type: "button", onClick: showSecretCode, component: "button", children: "Click here" }), ' ', "to display the setup key which can be manually entered in your authenticator app."] }) })] }) }), _jsx(Collapse, { in: isShowingSecretCode, children: _jsx(Box, { marginBottom: 2, children: _jsx(InputField, { label: "Setup Key", value: (mfaAuthenticatorAppSetup === null || mfaAuthenticatorAppSetup === void 0 ? void 0 : mfaAuthenticatorAppSetup.secretCode) || '', variant: "filled", focused: false, sx: {
42
+ input: {
43
+ cursor: 'default !important',
44
+ },
45
+ }, fullWidth: true, slotProps: {
46
+ input: {
47
+ readOnly: true,
48
+ endAdornment: (_jsx(CopyToClipBoardIconButton, { text: (mfaAuthenticatorAppSetup === null || mfaAuthenticatorAppSetup === void 0 ? void 0 : mfaAuthenticatorAppSetup.secretCode) || '' })),
49
+ },
50
+ }, helperText: _jsxs(_Fragment, { children: [_jsx(Link, { type: "button", onClick: hideSecretCode, component: "button", children: "Click here" }), ' ', "to hide the setup key"] }) }) }) }), _jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: "Verify App" }), _jsx(Typography, { variant: "body2", sx: { mb: 2 }, children: "Enter the 6-digit code found in your authenticator app." }), _jsx(InputField, { autoFocus: true, margin: "none", name: "code", label: "Code", fullWidth: true, placeholder: "XXXXXX", variant: "outlined", value: code, onChange: (event) => {
51
+ const newValue = event.target.value;
52
+ setState(() => newValue);
53
+ }, disabled: isSaving, "data-cypress": "mfa-authenticator-app-code" })] }), _jsxs(DialogActions, { children: [_jsx(Button, { type: "button", onClick: cancelMfaAuthenticatorAppSetup, disabled: isSaving, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "contained", color: "primary", disabled: !code || isSaving, children: "Save" })] })] }) }) }));
54
+ }
55
+ /**
56
+ * React Component that guides users through authenticator app MFA setup,
57
+ * including QR code scanning and verification code entry. Typically rendered by
58
+ * `<MultiFactorAuthentication />` within an
59
+ * `<MfaProvider />` tree.
60
+ *
61
+ * @returns
62
+ */
63
+ export default React.memo(MfaAuthenticatorAppDialog);
64
+ //# sourceMappingURL=MfaAuthenticatorAppDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MfaAuthenticatorAppDialog.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaAuthenticatorAppDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EACL,GAAG,EACH,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,IA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,EAEb,KAAC,UAAU,IACT,SAAS,QACT,MAAM,EAAC,MAAM,EACb,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,MAAM,EACZ,SAAS,QACT,WAAW,EAAC,QAAQ,EACpB,OAAO,EAAC,UAAU,EAClB,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;oCAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA;oCACnC,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAA;gCAC1B,CAAC,EACD,QAAQ,EAAE,QAAQ,kBACL,4BAA4B,GACzC,IACY,EAChB,MAAC,aAAa,eACZ,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,8BAA8B,EACvC,QAAQ,EAAE,QAAQ,uBAGX,EACT,KAAC,MAAM,IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAC,WAAW,EACnB,KAAK,EAAC,SAAS,EACf,QAAQ,EAAE,CAAC,IAAI,IAAI,QAAQ,qBAGpB,IACK,IACX,GACA,GACM,CAClB,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { QRCodeSVG } from 'qrcode.react'\nimport {\n Box,\n Collapse,\n Dialog,\n Grid,\n Link,\n Typography,\n DialogContent,\n DialogActions,\n Button,\n DialogTitle,\n} from '@mui/material'\nimport { authService } from '../../apps'\nimport useBooleanState from '../../hooks/useBooleanState'\nimport useMfa from '../../hooks/useMfa'\nimport { CopyToClipBoardIconButton } from '../CopyToClipboardIconButton'\nimport InputField from '../InputField'\n\nfunction MfaAuthenticatorAppDialog() {\n const {\n mfaAuthenticatorAppSetup,\n cancelMfaAuthenticatorAppSetup,\n completeMfaAuthenticatorAppSetup,\n } = useMfa()\n\n const [code, setState] = React.useState('')\n const [isShowingSecretCode, showSecretCode, hideSecretCode] =\n useBooleanState(false)\n\n const qrcodeValue = React.useMemo(() => {\n if (mfaAuthenticatorAppSetup) {\n return authService.generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup,\n )\n }\n }, [mfaAuthenticatorAppSetup])\n\n const [isSaving, startSaving, stopSaving] = useBooleanState(false)\n const handleSubmit = React.useCallback(\n async (event: React.SubmitEvent<HTMLFormElement>) => {\n event.preventDefault()\n\n if (!code || !mfaAuthenticatorAppSetup || isSaving) {\n return\n }\n\n startSaving()\n try {\n await mfaAuthenticatorAppSetup.mfaCodeCallback(code)\n await completeMfaAuthenticatorAppSetup()\n } finally {\n stopSaving()\n }\n },\n [\n code,\n completeMfaAuthenticatorAppSetup,\n isSaving,\n mfaAuthenticatorAppSetup,\n startSaving,\n stopSaving,\n ],\n )\n\n return (\n <React.Fragment>\n <Dialog\n open={!!mfaAuthenticatorAppSetup}\n onClose={cancelMfaAuthenticatorAppSetup}\n title=\"Complete MFA Setup\"\n >\n <form onSubmit={handleSubmit}>\n <DialogTitle>Authenticator App Setup</DialogTitle>\n <DialogContent dividers>\n <Typography variant=\"body2\" component=\"p\" sx={{ mb: 2 }}>\n Authenticator apps like{' '}\n <Link\n href=\"https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Google Authenticator\n </Link>{' '}\n and{' '}\n <Link\n href=\"https://www.microsoft.com/en-us/security/mobile-authenticator-app\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Microsoft Authenticator\n </Link>{' '}\n generate one-time passwords that are used as a second factor to\n verify your identity when prompted during sign-in.\n </Typography>\n <Typography variant=\"subtitle2\" gutterBottom>\n Scan the QR code\n </Typography>\n <Typography variant=\"body2\" sx={{ mb: 2 }}>\n Use an authenticator app or browser extension to scan the QR code\n below.\n </Typography>\n\n <Box marginBottom={2}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid>\n <Box\n border={1}\n padding={2}\n borderRadius={1}\n borderColor=\"divider\"\n display=\"inline-block\"\n lineHeight={0}\n >\n <QRCodeSVG value={qrcodeValue || ''} />\n </Box>\n </Grid>\n <Grid size={{ xs: 'grow' }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n Having trouble scanning the QR code?{' '}\n <Link\n type=\"button\"\n onClick={showSecretCode}\n component=\"button\"\n >\n Click here\n </Link>{' '}\n to display the setup key which can be manually entered in\n your authenticator app.\n </Typography>\n </Grid>\n </Grid>\n </Box>\n\n <Collapse in={isShowingSecretCode}>\n <Box marginBottom={2}>\n <InputField\n label=\"Setup Key\"\n value={mfaAuthenticatorAppSetup?.secretCode || ''}\n variant=\"filled\"\n focused={false}\n sx={{\n input: {\n cursor: 'default !important',\n },\n }}\n fullWidth\n slotProps={{\n input: {\n readOnly: true,\n endAdornment: (\n <CopyToClipBoardIconButton\n text={mfaAuthenticatorAppSetup?.secretCode || ''}\n />\n ),\n },\n }}\n helperText={\n <>\n <Link\n type=\"button\"\n onClick={hideSecretCode}\n component=\"button\"\n >\n Click here\n </Link>{' '}\n to hide the setup key\n </>\n }\n />\n </Box>\n </Collapse>\n\n <Typography variant=\"subtitle2\" gutterBottom>\n Verify App\n </Typography>\n <Typography variant=\"body2\" sx={{ mb: 2 }}>\n Enter the 6-digit code found in your authenticator app.\n </Typography>\n\n <InputField\n autoFocus\n margin=\"none\"\n name=\"code\"\n label=\"Code\"\n fullWidth\n placeholder=\"XXXXXX\"\n variant=\"outlined\"\n value={code}\n onChange={(event) => {\n const newValue = event.target.value\n setState(() => newValue)\n }}\n disabled={isSaving}\n data-cypress=\"mfa-authenticator-app-code\"\n />\n </DialogContent>\n <DialogActions>\n <Button\n type=\"button\"\n onClick={cancelMfaAuthenticatorAppSetup}\n disabled={isSaving}\n >\n Cancel\n </Button>\n <Button\n type=\"submit\"\n variant=\"contained\"\n color=\"primary\"\n disabled={!code || isSaving}\n >\n Save\n </Button>\n </DialogActions>\n </form>\n </Dialog>\n </React.Fragment>\n )\n}\n\n/**\n * React Component that guides users through authenticator app MFA setup,\n * including QR code scanning and verification code entry. Typically rendered by\n * `<MultiFactorAuthentication />` within an\n * `<MfaProvider />` tree.\n *\n * @returns\n */\nexport default React.memo(MfaAuthenticatorAppDialog)\n"]}
@@ -0,0 +1,10 @@
1
+ declare function MfaDisableDialog(): import("react/jsx-runtime").JSX.Element;
2
+ /**
3
+ * React Component that prompts the user to confirm disabling an MFA method.
4
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
5
+ * />` tree.
6
+ *
7
+ * @returns
8
+ */
9
+ declare const _default: import("react").MemoExoticComponent<typeof MfaDisableDialog>;
10
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { Typography } from '@mui/material';
4
+ import ConfirmDialog from '../ConfirmDialog';
5
+ import MaterialIcon from '../MaterialIcon';
6
+ import useMfa from '../../hooks/useMfa';
7
+ const methodLabels = {
8
+ authenticator: 'Authenticator App',
9
+ sms: 'SMS',
10
+ };
11
+ function MfaDisableDialog() {
12
+ const { disablingMfaMethod, completeDisablingMfa, cancelDisablingMfa, } = useMfa();
13
+ const methodLabel = disablingMfaMethod
14
+ ? methodLabels[disablingMfaMethod]
15
+ : 'MFA';
16
+ return (_jsx(ConfirmDialog, { isOpen: !!disablingMfaMethod, onClose: cancelDisablingMfa, onConfirm: completeDisablingMfa, title: "Please Confirm", confirmButtonText: `Disable ${methodLabel}`, confirmButtonIcon: _jsx(MaterialIcon, { children: "remove_moderator" }), cypress: {
17
+ dialog: 'disable-mfa-dialog',
18
+ confirmButton: 'disable-mfa-dialog-confirm-button',
19
+ cancelButton: 'disable-mfa-dialog-cancel-button',
20
+ error: 'disable-mfa-dialog-error-message',
21
+ }, children: _jsxs(Typography, { variant: "body2", children: ["Are you sure you want to disable ", methodLabel, " multi factor authentication (MFA)?"] }) }));
22
+ }
23
+ /**
24
+ * React Component that prompts the user to confirm disabling an MFA method.
25
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
26
+ * />` tree.
27
+ *
28
+ * @returns
29
+ */
30
+ export default memo(MfaDisableDialog);
31
+ //# sourceMappingURL=MfaDisableDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MfaDisableDialog.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaDisableDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAC5C,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,MAAM,YAAY,GAAG;IACnB,aAAa,EAAE,mBAAmB;IAClC,GAAG,EAAE,KAAK;CACF,CAAA;AAEV,SAAS,gBAAgB;IACvB,MAAM,EACJ,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,GACnB,GAAG,MAAM,EAAE,CAAA;IAEZ,MAAM,WAAW,GAAG,kBAAkB;QACpC,CAAC,CAAC,YAAY,CAAC,kBAAkB,CAAC;QAClC,CAAC,CAAC,KAAK,CAAA;IAET,OAAO,CACL,KAAC,aAAa,IACZ,MAAM,EAAE,CAAC,CAAC,kBAAkB,EAC5B,OAAO,EAAE,kBAAkB,EAC3B,SAAS,EAAE,oBAAoB,EAC/B,KAAK,EAAC,gBAAgB,EACtB,iBAAiB,EAAE,WAAW,WAAW,EAAE,EAC3C,iBAAiB,EAAE,KAAC,YAAY,mCAAgC,EAChE,OAAO,EAAE;YACP,MAAM,EAAE,oBAAoB;YAC5B,aAAa,EAAE,mCAAmC;YAClD,YAAY,EAAE,kCAAkC;YAChD,KAAK,EAAE,kCAAkC;SAC1C,YAED,MAAC,UAAU,IAAC,OAAO,EAAC,OAAO,kDACS,WAAW,2CAElC,GACC,CACjB,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,eAAe,IAAI,CAAC,gBAAgB,CAAC,CAAA","sourcesContent":["import { memo } from 'react'\nimport { Typography } from '@mui/material'\nimport ConfirmDialog from '../ConfirmDialog'\nimport MaterialIcon from '../MaterialIcon'\nimport useMfa from '../../hooks/useMfa'\n\nconst methodLabels = {\n authenticator: 'Authenticator App',\n sms: 'SMS',\n} as const\n\nfunction MfaDisableDialog() {\n const {\n disablingMfaMethod,\n completeDisablingMfa,\n cancelDisablingMfa,\n } = useMfa()\n\n const methodLabel = disablingMfaMethod\n ? methodLabels[disablingMfaMethod]\n : 'MFA'\n\n return (\n <ConfirmDialog\n isOpen={!!disablingMfaMethod}\n onClose={cancelDisablingMfa}\n onConfirm={completeDisablingMfa}\n title=\"Please Confirm\"\n confirmButtonText={`Disable ${methodLabel}`}\n confirmButtonIcon={<MaterialIcon>remove_moderator</MaterialIcon>}\n cypress={{\n dialog: 'disable-mfa-dialog',\n confirmButton: 'disable-mfa-dialog-confirm-button',\n cancelButton: 'disable-mfa-dialog-cancel-button',\n error: 'disable-mfa-dialog-error-message',\n }}\n >\n <Typography variant=\"body2\">\n Are you sure you want to disable {methodLabel} multi factor\n authentication (MFA)?\n </Typography>\n </ConfirmDialog>\n )\n}\n\n/**\n * React Component that prompts the user to confirm disabling an MFA method.\n * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider\n * />` tree.\n *\n * @returns\n */\nexport default memo(MfaDisableDialog)\n"]}
@@ -0,0 +1,10 @@
1
+ declare function MfaErrorSnackbar(): import("react/jsx-runtime").JSX.Element;
2
+ /**
3
+ * React Component that displays MFA setup errors from the `useMfa()` hook.
4
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
5
+ * />` tree.
6
+ *
7
+ * @returns
8
+ */
9
+ declare const _default: import("react").MemoExoticComponent<typeof MfaErrorSnackbar>;
10
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import useMfa from '../../hooks/useMfa';
4
+ import ErrorSnackbar from '../ErrorSnackbar';
5
+ function MfaErrorSnackbar() {
6
+ const { setupError, clearMfaSetupError } = useMfa();
7
+ return (_jsx(ErrorSnackbar, { open: !!setupError, onClose: clearMfaSetupError, children: _jsx("span", { "data-cypress": "mfa-setup-error-message", children: setupError === null || setupError === void 0 ? void 0 : setupError.message }) }));
8
+ }
9
+ /**
10
+ * React Component that displays MFA setup errors from the `useMfa()` hook.
11
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
12
+ * />` tree.
13
+ *
14
+ * @returns
15
+ */
16
+ export default memo(MfaErrorSnackbar);
17
+ //# sourceMappingURL=MfaErrorSnackbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MfaErrorSnackbar.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaErrorSnackbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C,SAAS,gBAAgB;IACvB,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,MAAM,EAAE,CAAA;IAEnD,OAAO,CACL,KAAC,aAAa,IAAC,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,kBAAkB,YAC5D,+BAAmB,yBAAyB,YAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,GAAQ,GAC3D,CACjB,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,eAAe,IAAI,CAAC,gBAAgB,CAAC,CAAA","sourcesContent":["import { memo } from 'react'\nimport useMfa from '../../hooks/useMfa'\nimport ErrorSnackbar from '../ErrorSnackbar'\n\nfunction MfaErrorSnackbar() {\n const { setupError, clearMfaSetupError } = useMfa()\n\n return (\n <ErrorSnackbar open={!!setupError} onClose={clearMfaSetupError}>\n <span data-cypress=\"mfa-setup-error-message\">{setupError?.message}</span>\n </ErrorSnackbar>\n )\n}\n\n/**\n * React Component that displays MFA setup errors from the `useMfa()` hook.\n * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider\n * />` tree.\n *\n * @returns\n */\nexport default memo(MfaErrorSnackbar)\n"]}
@@ -0,0 +1,19 @@
1
+ type Props = {
2
+ isEnabled: boolean;
3
+ isPreferred: boolean;
4
+ isSettingUp: boolean;
5
+ isSettingPreferredMfaMethod: boolean;
6
+ isSetupDisabled: boolean;
7
+ showSetupErrorTooltip?: boolean;
8
+ title: string;
9
+ description: string;
10
+ detail?: string;
11
+ cypressPrefix: string;
12
+ extraButtons?: React.ReactNode;
13
+ onSetup: () => void;
14
+ onDisable: () => void;
15
+ onSetPreferred: () => void;
16
+ };
17
+ declare function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }: Props): import("react/jsx-runtime").JSX.Element;
18
+ declare const _default: import("react").MemoExoticComponent<typeof MfaMethodRow>;
19
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { Box, Button, Chip, Grid, Tooltip, Typography } from '@mui/material';
4
+ function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }) {
5
+ return (_jsx(Box, { "data-cypress": `${cypressPrefix}-method-row`, children: _jsxs(Grid, { container: true, spacing: 2, alignItems: "center", children: [_jsxs(Grid, { size: { xs: 'grow' }, children: [_jsxs(Box, { sx: { mb: 1 }, children: [_jsx(Typography, { variant: "subtitle1", component: "span", children: title }), isEnabled && (_jsx(Chip, { size: "small", label: "Enabled", color: "info", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-status-chip` })), isPreferred && (_jsx(Chip, { size: "small", label: "Preferred", color: "success", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-preferred-chip` }))] }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: description }), !!detail && (_jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mt: 1 }, children: detail }))] }), _jsx(Grid, { size: "auto", children: _jsxs(Box, { display: "flex", gap: 1, flexWrap: "wrap", justifyContent: "flex-end", children: [extraButtons, isEnabled ? (_jsxs(_Fragment, { children: [!isPreferred && (_jsx(Button, { size: "small", variant: "outlined", loading: isSettingPreferredMfaMethod, disabled: isSettingPreferredMfaMethod, onClick: onSetPreferred, "data-cypress": `${cypressPrefix}-set-preferred-button`, children: "Set as Preferred" })), _jsx(Button, { size: "small", variant: "outlined", onClick: onDisable, "data-cypress": `${cypressPrefix}-disable-button`, children: "Disable" })] })) : (_jsx(Tooltip, { title: showSetupErrorTooltip
6
+ ? 'We are unable to load your MFA status. Please try again by clicking the reload button on the chip above.'
7
+ : '', children: _jsx("span", { children: _jsx(Button, { size: "small", variant: "contained", loading: isSettingUp, disabled: isSetupDisabled, onClick: onSetup, "data-cypress": `${cypressPrefix}-setup-button`, children: "Setup" }) }) }))] }) })] }) }));
8
+ }
9
+ export default memo(MfaMethodRow);
10
+ //# sourceMappingURL=MfaMethodRow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MfaMethodRow.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaMethodRow.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAmB5E,SAAS,YAAY,CAAC,EACpB,SAAS,EACT,WAAW,EACX,WAAW,EACX,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,KAAK,EACL,W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YAAY,EACZ,SAAS,CAAC,CAAC,CAAC,CACX,8BACG,CAAC,WAAW,IAAI,CACf,KAAC,MAAM,IACL,IAAI,EAAC,OAAO,EACZ,OAAO,EAAC,UAAU,EAClB,OAAO,EAAE,2BAA2B,EACpC,QAAQ,EAAE,2BAA2B,EACrC,OAAO,EAAE,cAAc,kBACT,GAAG,aAAa,uBAAuB,iCAG9C,CACV,EACD,KAAC,MAAM,IACL,IAAI,EAAC,OAAO,EACZ,OAAO,EAAC,UAAU,EAClB,OAAO,EAAE,SAAS,kBACJ,GAAG,aAAa,iBAAiB,wBAGxC,IACR,CACJ,CAAC,CAAC,CAAC,CACF,KAAC,OAAO,IACN,KAAK,EACH,qBAAqB;oCACnB,CAAC,CAAC,0GAA0G;oCAC5G,CAAC,CAAC,EAAE,YAGR,yBACE,KAAC,MAAM,IACL,IAAI,EAAC,OAAO,EACZ,OAAO,EAAC,WAAW,EACnB,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,OAAO,kBACF,GAAG,aAAa,eAAe,sBAGtC,GACJ,GACC,CACX,IACG,GACD,IACF,GACH,CACP,CAAA;AACH,CAAC;AAED,eAAe,IAAI,CAAC,YAAY,CAAC,CAAA","sourcesContent":["import { memo } from 'react'\nimport { Box, Button, Chip, Grid, Tooltip, Typography } from '@mui/material'\n\ntype Props = {\n isEnabled: boolean\n isPreferred: boolean\n isSettingUp: boolean\n isSettingPreferredMfaMethod: boolean\n isSetupDisabled: boolean\n showSetupErrorTooltip?: boolean\n title: string\n description: string\n detail?: string\n cypressPrefix: string\n extraButtons?: React.ReactNode\n onSetup: () => void\n onDisable: () => void\n onSetPreferred: () => void\n}\n\nfunction MfaMethodRow({\n isEnabled,\n isPreferred,\n isSettingUp,\n isSettingPreferredMfaMethod,\n isSetupDisabled,\n showSetupErrorTooltip,\n title,\n description,\n detail,\n cypressPrefix,\n extraButtons,\n onSetup,\n onDisable,\n onSetPreferred,\n}: Props) {\n return (\n <Box data-cypress={`${cypressPrefix}-method-row`}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid size={{ xs: 'grow' }}>\n <Box sx={{ mb: 1 }}>\n <Typography variant=\"subtitle1\" component=\"span\">\n {title}\n </Typography>\n {isEnabled && (\n <Chip\n size=\"small\"\n label=\"Enabled\"\n color=\"info\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-status-chip`}\n />\n )}\n {isPreferred && (\n <Chip\n size=\"small\"\n label=\"Preferred\"\n color=\"success\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-preferred-chip`}\n />\n )}\n </Box>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {description}\n </Typography>\n {!!detail && (\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ mt: 1 }}>\n {detail}\n </Typography>\n )}\n </Grid>\n <Grid size=\"auto\">\n <Box display=\"flex\" gap={1} flexWrap=\"wrap\" justifyContent=\"flex-end\">\n {extraButtons}\n {isEnabled ? (\n <>\n {!isPreferred && (\n <Button\n size=\"small\"\n variant=\"outlined\"\n loading={isSettingPreferredMfaMethod}\n disabled={isSettingPreferredMfaMethod}\n onClick={onSetPreferred}\n data-cypress={`${cypressPrefix}-set-preferred-button`}\n >\n Set as Preferred\n </Button>\n )}\n <Button\n size=\"small\"\n variant=\"outlined\"\n onClick={onDisable}\n data-cypress={`${cypressPrefix}-disable-button`}\n >\n Disable\n </Button>\n </>\n ) : (\n <Tooltip\n title={\n showSetupErrorTooltip\n ? 'We are unable to load your MFA status. Please try again by clicking the reload button on the chip above.'\n : ''\n }\n >\n <span>\n <Button\n size=\"small\"\n variant=\"contained\"\n loading={isSettingUp}\n disabled={isSetupDisabled}\n onClick={onSetup}\n data-cypress={`${cypressPrefix}-setup-button`}\n >\n Setup\n </Button>\n </span>\n </Tooltip>\n )}\n </Box>\n </Grid>\n </Grid>\n </Box>\n )\n}\n\nexport default memo(MfaMethodRow)\n"]}
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ declare function MfaPhoneNumberDialog(): import("react/jsx-runtime").JSX.Element;
3
+ /**
4
+ * React Component that lets users enter and verify a phone number for SMS MFA.
5
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
6
+ * />` tree.
7
+ *
8
+ * @returns
9
+ */
10
+ declare const _default: React.MemoExoticComponent<typeof MfaPhoneNumberDialog>;
11
+ export default _default;
@@ -0,0 +1,120 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { Dialog, DialogActions, DialogContent, DialogTitle, Button, Typography, Box, } from '@mui/material';
4
+ import useBooleanState from '../../hooks/useBooleanState';
5
+ import useMfa from '../../hooks/useMfa';
6
+ import InputField from '../InputField';
7
+ const PHONE_VERIFICATION_RESEND_COOL_DOWN_SECONDS = 60;
8
+ function getResendCoolDownRemainingSeconds(sentAt, now) {
9
+ if (!sentAt) {
10
+ return 0;
11
+ }
12
+ const elapsedSeconds = Math.floor((now - sentAt) / 1000);
13
+ return Math.max(0, PHONE_VERIFICATION_RESEND_COOL_DOWN_SECONDS - elapsedSeconds);
14
+ }
15
+ function usePhoneVerificationResendCoolDown(sentAt) {
16
+ const [now, setNow] = React.useState(() => Date.now());
17
+ const remainingSeconds = getResendCoolDownRemainingSeconds(sentAt, now);
18
+ React.useEffect(() => {
19
+ if (!sentAt) {
20
+ return;
21
+ }
22
+ const remaining = getResendCoolDownRemainingSeconds(sentAt, Date.now());
23
+ if (remaining <= 0) {
24
+ return;
25
+ }
26
+ const intervalId = window.setInterval(() => {
27
+ setNow(Date.now());
28
+ }, 1000);
29
+ return () => window.clearInterval(intervalId);
30
+ }, [sentAt]);
31
+ return remainingSeconds;
32
+ }
33
+ function MfaPhoneNumberDialog() {
34
+ const { isPhoneNumberDialogOpen, mfaSettings, phoneVerificationCodeSentAt, closePhoneNumberDialog, savePhoneNumber, verifyPhoneNumber, resendPhoneNumberVerificationCode, } = useMfa();
35
+ const isPhoneVerificationRequired = phoneVerificationCodeSentAt !== undefined;
36
+ const [phoneNumber, setPhoneNumber] = React.useState('');
37
+ const [verificationCode, setVerificationCode] = React.useState('');
38
+ const resendCoolDownSeconds = usePhoneVerificationResendCoolDown(phoneVerificationCodeSentAt);
39
+ const [isSaving, startSaving, stopSaving] = useBooleanState(false);
40
+ const [isResending, startResending, stopResending] = useBooleanState(false);
41
+ React.useEffect(() => {
42
+ if (isPhoneNumberDialogOpen) {
43
+ setPhoneNumber(mfaSettings.sms.phoneNumber || '');
44
+ setVerificationCode('');
45
+ }
46
+ }, [isPhoneNumberDialogOpen, mfaSettings.sms.phoneNumber]);
47
+ const handleSavePhoneNumber = React.useCallback(async () => {
48
+ startSaving();
49
+ try {
50
+ await savePhoneNumber(phoneNumber);
51
+ }
52
+ finally {
53
+ stopSaving();
54
+ }
55
+ }, [phoneNumber, savePhoneNumber, startSaving, stopSaving]);
56
+ const handleVerifyPhoneNumber = React.useCallback(async () => {
57
+ startSaving();
58
+ try {
59
+ await verifyPhoneNumber(verificationCode);
60
+ }
61
+ finally {
62
+ stopSaving();
63
+ }
64
+ }, [verificationCode, verifyPhoneNumber, startSaving, stopSaving]);
65
+ const handleSubmit = React.useCallback((event) => {
66
+ event.preventDefault();
67
+ if (isSaving) {
68
+ return;
69
+ }
70
+ if (isPhoneVerificationRequired) {
71
+ if (!verificationCode) {
72
+ return;
73
+ }
74
+ void handleVerifyPhoneNumber();
75
+ return;
76
+ }
77
+ if (!phoneNumber) {
78
+ return;
79
+ }
80
+ void handleSavePhoneNumber();
81
+ }, [
82
+ handleSavePhoneNumber,
83
+ handleVerifyPhoneNumber,
84
+ isPhoneVerificationRequired,
85
+ isSaving,
86
+ phoneNumber,
87
+ verificationCode,
88
+ ]);
89
+ const handleResendVerificationCode = React.useCallback(async () => {
90
+ startResending();
91
+ try {
92
+ await resendPhoneNumberVerificationCode();
93
+ }
94
+ finally {
95
+ stopResending();
96
+ }
97
+ }, [resendPhoneNumberVerificationCode, startResending, stopResending]);
98
+ return (_jsx(Dialog, { open: isPhoneNumberDialogOpen, onClose: () => {
99
+ if (!isSaving) {
100
+ closePhoneNumberDialog();
101
+ }
102
+ }, fullWidth: true, maxWidth: "sm", children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(DialogTitle, { children: isPhoneVerificationRequired
103
+ ? 'Verify Phone Number'
104
+ : 'Save Phone Number' }), _jsx(DialogContent, { dividers: true, children: isPhoneVerificationRequired ? (_jsxs(_Fragment, { children: [_jsxs(Typography, { variant: "body2", paragraph: true, children: ["Enter the verification code sent to ", phoneNumber, "."] }), _jsx(InputField, { autoFocus: true, margin: "none", name: "verificationCode", label: "Verification Code", fullWidth: true, placeholder: "XXXXXX", variant: "outlined", value: verificationCode, onChange: (event) => {
105
+ setVerificationCode(event.target.value);
106
+ }, disabled: isSaving, "data-cypress": "mfa-phone-verification-code" }, "verification-code"), _jsx(Box, { marginTop: 1, children: _jsx(Button, { type: "button", variant: "text", size: "small", disabled: resendCoolDownSeconds > 0 || isSaving || isResending, onClick: handleResendVerificationCode, "data-cypress": "mfa-phone-resend-button", children: resendCoolDownSeconds > 0
107
+ ? `Send again (${resendCoolDownSeconds}s)`
108
+ : 'Send again' }) })] })) : (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "body2", paragraph: true, children: "Enter your phone number to receive SMS verification codes when signing in." }), _jsx(InputField, { autoFocus: true, margin: "none", name: "phoneNumber", label: "Phone Number", fullWidth: true, placeholder: "+61400000000", variant: "outlined", value: phoneNumber, onChange: (event) => {
109
+ setPhoneNumber(event.target.value);
110
+ }, disabled: isSaving, helperText: "Include your country code, for example +61400000000.", "data-cypress": "mfa-phone-number" }, "phone-number")] })) }), _jsxs(DialogActions, { children: [_jsx(Button, { type: "button", onClick: closePhoneNumberDialog, disabled: isSaving, children: "Cancel" }), isPhoneVerificationRequired ? (_jsx(Button, { type: "submit", variant: "contained", disabled: !verificationCode || isSaving, "data-cypress": "mfa-phone-verify-button", children: "Verify" })) : (_jsx(Button, { type: "submit", variant: "contained", disabled: !phoneNumber || isSaving, "data-cypress": "mfa-phone-save-button", children: "Save" }))] })] }) }));
111
+ }
112
+ /**
113
+ * React Component that lets users enter and verify a phone number for SMS MFA.
114
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
115
+ * />` tree.
116
+ *
117
+ * @returns
118
+ */
119
+ export default React.memo(MfaPhoneNumberDialog);
120
+ //# sourceMappingURL=MfaPhoneNumberDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MfaPhoneNumberDialog.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaPhoneNumberDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,MAAM,EACN,aAAa,EACb,aAAa,EACb,WAAW,EACX,MAAM,EACN,UAAU,EACV,GAAG,GACJ,MAAM,eAAe,CAAA;AACtB,OAAO,eAAe,MAAM,6BAA6B,CAAA;AACzD,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,UAAU,MAAM,eAAe,CAAA;AAEtC,MAAM,2CAA2C,GAAG,EAAE,CAAA;AAEtD,SAAS,iCAAiC,CACxC,MAA0B,EAC1B,GAAW;IAEX,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;IACxD,OAAO,IAAI,CAAC,GAAG,CACb,CAAC,EACD,2CAA2C,GAAG,cAAc,CAC7D,CAAA;AACH,CAAC;AAED,SAAS,kCAAkC,CAAC,MAA0B;IACpE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAEtD,MAAM,gBAAgB,GAAG,iCAAiC,CAAC,MA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IACL,IAAI,EAAC,QAAQ,EACb,OAAO,EAAC,WAAW,EACnB,QAAQ,EAAE,CAAC,WAAW,IAAI,QAAQ,kBACrB,uBAAuB,qBAG7B,CACV,IACa,IACX,GACA,CACV,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport {\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Button,\n Typography,\n Box,\n} from '@mui/material'\nimport useBooleanState from '../../hooks/useBooleanState'\nimport useMfa from '../../hooks/useMfa'\nimport InputField from '../InputField'\n\nconst PHONE_VERIFICATION_RESEND_COOL_DOWN_SECONDS = 60\n\nfunction getResendCoolDownRemainingSeconds(\n sentAt: number | undefined,\n now: number,\n) {\n if (!sentAt) {\n return 0\n }\n\n const elapsedSeconds = Math.floor((now - sentAt) / 1000)\n return Math.max(\n 0,\n PHONE_VERIFICATION_RESEND_COOL_DOWN_SECONDS - elapsedSeconds,\n )\n}\n\nfunction usePhoneVerificationResendCoolDown(sentAt: number | undefined) {\n const [now, setNow] = React.useState(() => Date.now())\n\n const remainingSeconds = getResendCoolDownRemainingSeconds(sentAt, now)\n\n React.useEffect(() => {\n if (!sentAt) {\n return\n }\n\n const remaining = getResendCoolDownRemainingSeconds(sentAt, Date.now())\n if (remaining <= 0) {\n return\n }\n\n const intervalId = window.setInterval(() => {\n setNow(Date.now())\n }, 1000)\n\n return () => window.clearInterval(intervalId)\n }, [sentAt])\n\n return remainingSeconds\n}\n\nfunction MfaPhoneNumberDialog() {\n const {\n isPhoneNumberDialogOpen,\n mfaSettings,\n phoneVerificationCodeSentAt,\n closePhoneNumberDialog,\n savePhoneNumber,\n verifyPhoneNumber,\n resendPhoneNumberVerificationCode,\n } = useMfa()\n\n const isPhoneVerificationRequired = phoneVerificationCodeSentAt !== undefined\n\n const [phoneNumber, setPhoneNumber] = React.useState('')\n const [verificationCode, setVerificationCode] = React.useState('')\n const resendCoolDownSeconds = usePhoneVerificationResendCoolDown(\n phoneVerificationCodeSentAt,\n )\n const [isSaving, startSaving, stopSaving] = useBooleanState(false)\n const [isResending, startResending, stopResending] = useBooleanState(false)\n\n React.useEffect(() => {\n if (isPhoneNumberDialogOpen) {\n setPhoneNumber(mfaSettings.sms.phoneNumber || '')\n setVerificationCode('')\n }\n }, [isPhoneNumberDialogOpen, mfaSettings.sms.phoneNumber])\n\n const handleSavePhoneNumber = React.useCallback(async () => {\n startSaving()\n try {\n await savePhoneNumber(phoneNumber)\n } finally {\n stopSaving()\n }\n }, [phoneNumber, savePhoneNumber, startSaving, stopSaving])\n\n const handleVerifyPhoneNumber = React.useCallback(async () => {\n startSaving()\n try {\n await verifyPhoneNumber(verificationCode)\n } finally {\n stopSaving()\n }\n }, [verificationCode, verifyPhoneNumber, startSaving, stopSaving])\n\n const handleSubmit = React.useCallback(\n (event: React.SubmitEvent<HTMLFormElement>) => {\n event.preventDefault()\n\n if (isSaving) {\n return\n }\n\n if (isPhoneVerificationRequired) {\n if (!verificationCode) {\n return\n }\n\n void handleVerifyPhoneNumber()\n return\n }\n\n if (!phoneNumber) {\n return\n }\n\n void handleSavePhoneNumber()\n },\n [\n handleSavePhoneNumber,\n handleVerifyPhoneNumber,\n isPhoneVerificationRequired,\n isSaving,\n phoneNumber,\n verificationCode,\n ],\n )\n\n const handleResendVerificationCode = React.useCallback(async () => {\n startResending()\n try {\n await resendPhoneNumberVerificationCode()\n } finally {\n stopResending()\n }\n }, [resendPhoneNumberVerificationCode, startResending, stopResending])\n\n return (\n <Dialog\n open={isPhoneNumberDialogOpen}\n onClose={() => {\n if (!isSaving) {\n closePhoneNumberDialog()\n }\n }}\n fullWidth\n maxWidth=\"sm\"\n >\n <form onSubmit={handleSubmit}>\n <DialogTitle>\n {isPhoneVerificationRequired\n ? 'Verify Phone Number'\n : 'Save Phone Number'}\n </DialogTitle>\n <DialogContent dividers>\n {isPhoneVerificationRequired ? (\n <>\n <Typography variant=\"body2\" paragraph>\n Enter the verification code sent to {phoneNumber}.\n </Typography>\n <InputField\n key=\"verification-code\"\n autoFocus\n margin=\"none\"\n name=\"verificationCode\"\n label=\"Verification Code\"\n fullWidth\n placeholder=\"XXXXXX\"\n variant=\"outlined\"\n value={verificationCode}\n onChange={(event) => {\n setVerificationCode(event.target.value)\n }}\n disabled={isSaving}\n data-cypress=\"mfa-phone-verification-code\"\n />\n <Box marginTop={1}>\n <Button\n type=\"button\"\n variant=\"text\"\n size=\"small\"\n disabled={\n resendCoolDownSeconds > 0 || isSaving || isResending\n }\n onClick={handleResendVerificationCode}\n data-cypress=\"mfa-phone-resend-button\"\n >\n {resendCoolDownSeconds > 0\n ? `Send again (${resendCoolDownSeconds}s)`\n : 'Send again'}\n </Button>\n </Box>\n </>\n ) : (\n <>\n <Typography variant=\"body2\" paragraph>\n Enter your phone number to receive SMS verification codes when\n signing in.\n </Typography>\n <InputField\n key=\"phone-number\"\n autoFocus\n margin=\"none\"\n name=\"phoneNumber\"\n label=\"Phone Number\"\n fullWidth\n placeholder=\"+61400000000\"\n variant=\"outlined\"\n value={phoneNumber}\n onChange={(event) => {\n setPhoneNumber(event.target.value)\n }}\n disabled={isSaving}\n helperText=\"Include your country code, for example +61400000000.\"\n data-cypress=\"mfa-phone-number\"\n />\n </>\n )}\n </DialogContent>\n <DialogActions>\n <Button\n type=\"button\"\n onClick={closePhoneNumberDialog}\n disabled={isSaving}\n >\n Cancel\n </Button>\n {isPhoneVerificationRequired ? (\n <Button\n type=\"submit\"\n variant=\"contained\"\n disabled={!verificationCode || isSaving}\n data-cypress=\"mfa-phone-verify-button\"\n >\n Verify\n </Button>\n ) : (\n <Button\n type=\"submit\"\n variant=\"contained\"\n disabled={!phoneNumber || isSaving}\n data-cypress=\"mfa-phone-save-button\"\n >\n Save\n </Button>\n )}\n </DialogActions>\n </form>\n </Dialog>\n )\n}\n\n/**\n * React Component that lets users enter and verify a phone number for SMS MFA.\n * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider\n * />` tree.\n *\n * @returns\n */\nexport default React.memo(MfaPhoneNumberDialog)\n"]}
@@ -0,0 +1,10 @@
1
+ declare function MfaRemovePhoneNumberDialog(): import("react/jsx-runtime").JSX.Element;
2
+ /**
3
+ * React Component that prompts the user to confirm removing their phone number.
4
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
5
+ * />` tree.
6
+ *
7
+ * @returns
8
+ */
9
+ declare const _default: import("react").MemoExoticComponent<typeof MfaRemovePhoneNumberDialog>;
10
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { Typography } from '@mui/material';
4
+ import ConfirmDialog from '../ConfirmDialog';
5
+ import MaterialIcon from '../MaterialIcon';
6
+ import useMfa from '../../hooks/useMfa';
7
+ function MfaRemovePhoneNumberDialog() {
8
+ const { isRemovePhoneNumberDialogOpen, mfaSettings, completeRemovingPhoneNumber, cancelRemovingPhoneNumber, } = useMfa();
9
+ return (_jsx(ConfirmDialog, { isOpen: isRemovePhoneNumberDialogOpen, onClose: cancelRemovingPhoneNumber, onConfirm: completeRemovingPhoneNumber, title: "Please Confirm", confirmButtonText: "Remove Phone Number", confirmButtonIcon: _jsx(MaterialIcon, { children: "phone_disabled" }), cypress: {
10
+ dialog: 'remove-phone-number-dialog',
11
+ confirmButton: 'remove-phone-number-dialog-confirm-button',
12
+ cancelButton: 'remove-phone-number-dialog-cancel-button',
13
+ error: 'remove-phone-number-dialog-error-message',
14
+ }, children: _jsxs(Typography, { variant: "body2", children: ["Are you sure you want to remove ", mfaSettings.sms.phoneNumber, " from your account?"] }) }));
15
+ }
16
+ /**
17
+ * React Component that prompts the user to confirm removing their phone number.
18
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
19
+ * />` tree.
20
+ *
21
+ * @returns
22
+ */
23
+ export default memo(MfaRemovePhoneNumberDialog);
24
+ //# sourceMappingURL=MfaRemovePhoneNumberDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MfaRemovePhoneNumberDialog.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaRemovePhoneNumberDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAC5C,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,SAAS,0BAA0B;IACjC,MAAM,EACJ,6BAA6B,EAC7B,WAAW,EACX,2BAA2B,EAC3B,yBAAyB,GAC1B,GAAG,MAAM,EAAE,CAAA;IAEZ,OAAO,CACL,KAAC,aAAa,IACZ,MAAM,EAAE,6BAA6B,EACrC,OAAO,EAAE,yBAAyB,EAClC,SAAS,EAAE,2BAA2B,EACtC,KAAK,EAAC,gBAAgB,EACtB,iBAAiB,EAAC,qBAAqB,EACvC,iBAAiB,EAAE,KAAC,YAAY,iCAA8B,EAC9D,OAAO,EAAE;YACP,MAAM,EAAE,4BAA4B;YACpC,aAAa,EAAE,2CAA2C;YAC1D,YAAY,EAAE,0CAA0C;YACxD,KAAK,EAAE,0CAA0C;SAClD,YAED,MAAC,UAAU,IAAC,OAAO,EAAC,OAAO,iDACQ,WAAW,CAAC,GAAG,CAAC,WAAW,2BAEjD,GACC,CACjB,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,eAAe,IAAI,CAAC,0BAA0B,CAAC,CAAA","sourcesContent":["import { memo } from 'react'\r\nimport { Typography } from '@mui/material'\r\nimport ConfirmDialog from '../ConfirmDialog'\r\nimport MaterialIcon from '../MaterialIcon'\r\nimport useMfa from '../../hooks/useMfa'\r\n\r\nfunction MfaRemovePhoneNumberDialog() {\r\n const {\r\n isRemovePhoneNumberDialogOpen,\r\n mfaSettings,\r\n completeRemovingPhoneNumber,\r\n cancelRemovingPhoneNumber,\r\n } = useMfa()\r\n\r\n return (\r\n <ConfirmDialog\r\n isOpen={isRemovePhoneNumberDialogOpen}\r\n onClose={cancelRemovingPhoneNumber}\r\n onConfirm={completeRemovingPhoneNumber}\r\n title=\"Please Confirm\"\r\n confirmButtonText=\"Remove Phone Number\"\r\n confirmButtonIcon={<MaterialIcon>phone_disabled</MaterialIcon>}\r\n cypress={{\r\n dialog: 'remove-phone-number-dialog',\r\n confirmButton: 'remove-phone-number-dialog-confirm-button',\r\n cancelButton: 'remove-phone-number-dialog-cancel-button',\r\n error: 'remove-phone-number-dialog-error-message',\r\n }}\r\n >\r\n <Typography variant=\"body2\">\r\n Are you sure you want to remove {mfaSettings.sms.phoneNumber} from your\r\n account?\r\n </Typography>\r\n </ConfirmDialog>\r\n )\r\n}\r\n\r\n/**\r\n * React Component that prompts the user to confirm removing their phone number.\r\n * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider\r\n * />` tree.\r\n *\r\n * @returns\r\n */\r\nexport default memo(MfaRemovePhoneNumberDialog)\r\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * React Component that displays a status chip for the user's MFA status.
3
+ * Typically rendered by `<MultiFactorAuthentication />` within an `<MfaProvider
4
+ * />` tree.
5
+ *
6
+ * @returns
7
+ */
8
+ declare function MfaStatusChip(): import("react/jsx-runtime").JSX.Element | null;
9
+ declare const _default: import("react").MemoExoticComponent<typeof MfaStatusChip>;
10
+ export default _default;