-
Notifications
You must be signed in to change notification settings - Fork 6
fix(mfa-step): create a new step for handling MFA set up page text output callback script #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+547
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@forgerock/login-widget': patch | ||
| --- | ||
|
|
||
| Add dedicated MFA enrollment and recovery codes stages for multi-factor setup journeys, including a new `mfa-enrollment.svelte` stage that handles the MFA setup text-output callback script and a `recovery-codes.svelte` stage that displays one-time recovery codes after MFA registration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <!-- | ||
|
|
||
| Copyright © 2026 Ping Identity Corporation. All right reserved. | ||
|
|
||
| This software may be modified and distributed under the terms | ||
| of the MIT license. See the LICENSE file for details. | ||
|
|
||
| --> | ||
|
|
||
| <script lang="ts"> | ||
| import '../app.css'; | ||
| import { page } from '$app/stores'; | ||
|
|
||
| function getErrorMessage(err: unknown): string { | ||
| if (typeof err === 'string') { | ||
| return err; | ||
| } | ||
|
|
||
| const maybe = err as { message?: unknown; body?: { message?: unknown } } | null | undefined; | ||
| const message = maybe?.body?.message ?? maybe?.message; | ||
| return typeof message === 'string' ? message : 'An unexpected error occurred.'; | ||
| } | ||
|
|
||
| $: message = getErrorMessage($page.error); | ||
| </script> | ||
|
|
||
| <div | ||
| class="tw_bg-body-light dark:tw_bg-body-dark tw_min-h-screen tw_flex tw_items-center tw_justify-center tw_p-6" | ||
| > | ||
| <div | ||
| class="tw_containing-box dark:tw_containing-box_dark md:tw_containing-box_medium tw_flex tw_flex-col tw_items-center tw_text-center tw_gap-4" | ||
| > | ||
| <h1 class="tw_primary-header dark:tw_primary-header_dark">Configuration error</h1> | ||
| <p class="tw_text-secondary-dark dark:tw_text-secondary-light">{message}</p> | ||
| <p class="tw_text-secondary-dark dark:tw_text-secondary-light">Status: {$page.status}</p> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| <!-- | ||
|
|
||
| Copyright © 2025-2026 Ping Identity Corporation. All right reserved. | ||
|
|
||
| This software may be modified and distributed under the terms | ||
| of the MIT license. See the LICENSE file for details. | ||
|
|
||
| --> | ||
|
|
||
| <script lang="ts"> | ||
| import { callbackType } from '@forgerock/journey-client'; | ||
| import { afterUpdate } from 'svelte'; | ||
|
|
||
| import T from '$components/_utilities/locale-strings.svelte'; | ||
| import ShieldIcon from '$components/icons/shield-icon.svelte'; | ||
| // Import primitives | ||
| import Alert from '$components/primitives/alert/alert.svelte'; | ||
| import Button from '$components/primitives/button/button.svelte'; | ||
| import Form from '$components/primitives/form/form.svelte'; | ||
| import Text from '$components/primitives/text/text.svelte'; | ||
| // i18n | ||
| import { interpolate } from '$core/_utilities/i18n.utilities'; | ||
| import { convertStringToKey } from '$journey/stages/_utilities/step.utilities'; | ||
|
|
||
| import type { | ||
| ConfirmationCallback, | ||
| HiddenValueCallback, | ||
| JourneyStep, | ||
| } from '@forgerock/journey-client/types'; | ||
|
|
||
| // Types | ||
| import type { StageFormObject, StageJourneyObject } from '$journey/journey.interfaces'; | ||
|
|
||
| export let componentStyle: 'app' | 'inline' | 'modal'; | ||
| export let form: StageFormObject; | ||
| export let formEl: HTMLFormElement | null = null; | ||
| export let journey: StageJourneyObject; | ||
| export let step: JourneyStep; | ||
|
|
||
| type SubStage = 'enrollment' | 'getApp' | 'appLinks'; | ||
|
|
||
| const formFailureMessageId = 'mfaEnrollmentFailureMessage'; | ||
| const formHeaderId = 'mfaEnrollmentHeader'; | ||
| const formElementId = 'mfaEnrollmentForm'; | ||
|
|
||
| let alertNeedsFocus = false; | ||
| let formMessageKey = ''; | ||
| let formAriaDescriptor = formHeaderId; | ||
| let formNeedsFocus = false; | ||
| let subStage: SubStage = 'enrollment'; | ||
| let confirmationCb: ConfirmationCallback | null = null; | ||
| let hiddenValueCb: HiddenValueCallback | null = null; | ||
|
|
||
| afterUpdate(() => { | ||
| if (form?.message) { | ||
| formAriaDescriptor = formFailureMessageId; | ||
| alertNeedsFocus = true; | ||
| formNeedsFocus = false; | ||
| } else { | ||
| formAriaDescriptor = formHeaderId; | ||
| alertNeedsFocus = false; | ||
| formNeedsFocus = true; | ||
| } | ||
| }); | ||
|
|
||
| $: { | ||
| formMessageKey = convertStringToKey(form?.message); | ||
|
|
||
| const confirmationCbs = step.getCallbacksOfType( | ||
| callbackType.ConfirmationCallback, | ||
| ) as ConfirmationCallback[]; | ||
| confirmationCb = confirmationCbs[0] ?? null; | ||
|
|
||
| const hiddenCbs = step.getCallbacksOfType( | ||
| callbackType.HiddenValueCallback, | ||
| ) as HiddenValueCallback[]; | ||
| hiddenValueCb = hiddenCbs[0] ?? null; | ||
|
|
||
| const hiddenId = (hiddenValueCb?.getOutputByName('id', '') as string) ?? ''; | ||
|
|
||
| if (hiddenId.startsWith('getapp-')) { | ||
| subStage = 'getApp'; | ||
| } else if (hiddenId.startsWith('skip-')) { | ||
| subStage = 'enrollment'; | ||
| } else { | ||
| subStage = 'appLinks'; | ||
| } | ||
| } | ||
|
|
||
| function submitWithValue(value: string) { | ||
| confirmationCb?.setInputValue(value); | ||
| form?.submit(); | ||
| } | ||
|
|
||
| function submitHidden(value: string) { | ||
| hiddenValueCb?.setInputValue(value); | ||
| form?.submit(); | ||
| } | ||
| </script> | ||
|
|
||
| <Form | ||
| bind:formEl | ||
| ariaDescribedBy={formAriaDescriptor} | ||
| id={formElementId} | ||
| needsFocus={formNeedsFocus} | ||
| onSubmitWhenValid={() => form?.submit()} | ||
| > | ||
| {#if form?.icon && componentStyle !== 'inline'} | ||
| <div class="tw_flex tw_justify-center"> | ||
| <ShieldIcon classes="tw_text-gray-400 tw_fill-current" size="72px" /> | ||
| </div> | ||
| {/if} | ||
|
|
||
| {#if form?.message} | ||
| <Alert id={formFailureMessageId} needsFocus={alertNeedsFocus} type="error"> | ||
| {interpolate(formMessageKey, null, form?.message)} | ||
| </Alert> | ||
| {/if} | ||
|
|
||
| {#if subStage === 'enrollment'} | ||
| <header id={formHeaderId}> | ||
| <h1 class="tw_primary-header dark:tw_primary-header_dark"> | ||
| <T key="setupTwoStepVerification" /> | ||
| </h1> | ||
| <Text classes="tw_text-center tw_-mt-5 tw_mb-2 tw_py-4"> | ||
| <T key="setupTwoStepVerificationDescription" /> | ||
| </Text> | ||
| </header> | ||
|
|
||
| <Alert id="mfaWarning" needsFocus={false} type="warning"> | ||
| <T html={true} key="setupTwoStepVerificationWarning" /> | ||
| </Alert> | ||
|
|
||
| <Button | ||
| busy={journey?.loading} | ||
| style="primary" | ||
| type="button" | ||
| width="full" | ||
| onClick={() => submitWithValue('0')} | ||
| > | ||
| <T key="setupTwoStepVerificationButton" /> | ||
| </Button> | ||
|
|
||
| <p class="tw_my-4 tw_text-center tw_text-sm"> | ||
| <button | ||
| class="tw_text-link-dark dark:tw_text-link-light tw_underline" | ||
| type="button" | ||
| on:click={() => submitHidden('Skip')} | ||
| > | ||
| <T key="skipForNow" /> | ||
| </button> | ||
| </p> | ||
| {:else if subStage === 'getApp'} | ||
| <header id={formHeaderId}> | ||
| <h1 class="tw_primary-header dark:tw_primary-header_dark"> | ||
| <T key="getAuthenticatorApp" /> | ||
| </h1> | ||
| <Text classes="tw_text-center tw_-mt-5 tw_mb-2 tw_py-4"> | ||
| <T key="getAuthenticatorAppDescription" /> | ||
| </Text> | ||
| </header> | ||
|
|
||
| <Button | ||
| busy={journey?.loading} | ||
| style="primary" | ||
| type="button" | ||
| width="full" | ||
| onClick={() => submitWithValue('0')} | ||
| > | ||
| <T key="next" /> | ||
| </Button> | ||
|
|
||
| <p class="tw_my-4 tw_text-center tw_text-sm"> | ||
| <button | ||
| class="tw_text-link-dark dark:tw_text-link-light tw_underline" | ||
| type="button" | ||
| on:click={() => submitHidden('Get app')} | ||
| > | ||
| <T key="downloadTheApp" /> | ||
| </button> | ||
| </p> | ||
| {:else} | ||
| <header id={formHeaderId}> | ||
| <h1 class="tw_primary-header dark:tw_primary-header_dark"> | ||
| <T key="getAuthenticatorApp" /> | ||
| </h1> | ||
| <Text classes="tw_text-center tw_-mt-5 tw_mb-2 tw_py-4"> | ||
| <T html={true} key="getAuthenticatorAppLinks" /> | ||
| </Text> | ||
| </header> | ||
|
|
||
| <Button | ||
| busy={journey?.loading} | ||
| style="primary" | ||
| type="button" | ||
| width="full" | ||
| onClick={() => submitWithValue('0')} | ||
| > | ||
| <T key="continueButton" /> | ||
| </Button> | ||
| {/if} | ||
| </Form> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.