-
Notifications
You must be signed in to change notification settings - Fork 336
Add Organization Level TOTP Enrollment Configuration UI #9494
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9288f4e
add TOTP Authenticator Form
LinukaAr 524cfae
Add TOTP Authenticator Form and update related components
LinukaAr 148c40d
Fix TOTP authenticator configuration persistence
LinukaAr 29473ea
Remove debug logging
LinukaAr 3bad494
Address ESLint warnings
LinukaAr 75c3695
Merge remote-tracking branch 'origin/master' into totp-org-config
LinukaAr af4b7f3
Remove unused constants
LinukaAr 8c8185a
Merge branch 'wso2:master' into totp-org-config
LinukaAr 18f9928
Address comments
LinukaAr 95c521b
Add minor improvements
LinukaAr 58b3110
Merge branch 'wso2:master' into totp-org-config
LinukaAr a757fe4
Add Changeset 🦋
LinukaAr ab5d290
Remove unused import
LinukaAr f46a0e9
Update header
LinukaAr d9c4df0
Address Comments
LinukaAr 7e34c6b
Address eslint issues
LinukaAr ac84fec
Remove unused vars
LinukaAr 101d4b4
Add minor improvements
LinukaAr 72b4adb
Fix eslint issue
LinukaAr 0f520eb
Add Minor improvement
LinukaAr bcbe9b1
Add i18n to changeset
LinukaAr 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
Some comments aren't visible on the classic Files Changed page.
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,8 @@ | ||
| --- | ||
| "@wso2is/admin.identity-providers.v1": minor | ||
| "@wso2is/admin.connections.v1": minor | ||
| "@wso2is/console": minor | ||
LinukaAr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "@wso2is/i18n": patch | ||
| --- | ||
|
|
||
| Introduce a org level config to govern TOTP | ||
LinukaAr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
199 changes: 199 additions & 0 deletions
199
...res/admin.connections.v1/components/edit/forms/authenticators/totp-authenticator-form.tsx
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,199 @@ | ||
| /** | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { TestableComponentInterface } from "@wso2is/core/models"; | ||
| import { Field, Form } from "@wso2is/form"; | ||
| import isEmpty from "lodash-es/isEmpty"; | ||
| import React, { FunctionComponent, ReactElement, useEffect, useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { | ||
| CommonAuthenticatorFormInitialValuesInterface, | ||
| CommonAuthenticatorFormMetaInterface, | ||
| CommonAuthenticatorFormPropertyInterface | ||
| } from "../../../../models/authenticators"; | ||
| import { | ||
| CommonPluggableComponentPropertyInterface | ||
| } from "../../../../models/connection"; | ||
|
|
||
| interface TOTPAuthenticatorFormPropsInterface extends TestableComponentInterface { | ||
| /** | ||
| * TOTP Authenticator Metadata. | ||
| */ | ||
| metadata: CommonAuthenticatorFormMetaInterface; | ||
| /** | ||
| * TOTP Authenticator configured initial values. | ||
| */ | ||
| initialValues: CommonAuthenticatorFormInitialValuesInterface; | ||
| /** | ||
| * Callback for form submit. | ||
| * @param values - Resolved Form Values. | ||
| */ | ||
| onSubmit: (values: CommonAuthenticatorFormInitialValuesInterface) => void; | ||
| /** | ||
| * Is readonly. | ||
| */ | ||
| readOnly?: boolean; | ||
| /** | ||
| * Specifies if the form is submitting. | ||
| */ | ||
| isSubmitting?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Form initial values interface. | ||
| */ | ||
| interface TOTPAuthenticatorFormInitialValuesInterface { | ||
| /** | ||
| * Enable progressive enrollment. | ||
| */ | ||
| TOTP_EnrolUserInAuthenticationFlow: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Proptypes for the TOTP Authenticator Form error messages. | ||
| */ | ||
| export interface TOTPAuthenticatorFormErrorValidationsInterface { | ||
| /** | ||
| * Enable progressive enrollment. | ||
| */ | ||
| TOTP_EnrolUserInAuthenticationFlow: string; | ||
| } | ||
|
|
||
| const FORM_ID: string = "totp-authenticator-form"; | ||
|
|
||
LinukaAr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * TOTP Authenticator Form. | ||
| * | ||
| * @param props - Props injected to the component. | ||
| * @returns Functional component. | ||
| */ | ||
| export const TOTPAuthenticatorForm: FunctionComponent<TOTPAuthenticatorFormPropsInterface> = ( | ||
| props: TOTPAuthenticatorFormPropsInterface | ||
| ): ReactElement => { | ||
|
|
||
| const { | ||
| initialValues: originalInitialValues, | ||
LinukaAr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| onSubmit, | ||
| readOnly, | ||
| isSubmitting, | ||
| ["data-testid"]: testId | ||
| } = props; | ||
|
|
||
| const { t } = useTranslation(); | ||
|
|
||
| const [ initialValues, setInitialValues ] = useState<TOTPAuthenticatorFormInitialValuesInterface>(undefined); | ||
|
|
||
| /** | ||
| * Flattens and resolved form initial values and field metadata. | ||
| */ | ||
| useEffect(() => { | ||
|
|
||
| if (isEmpty(originalInitialValues?.properties)) { | ||
| return; | ||
| } | ||
|
|
||
| let resolvedInitialValues: TOTPAuthenticatorFormInitialValuesInterface = null; | ||
|
|
||
| originalInitialValues.properties.forEach((value: CommonAuthenticatorFormPropertyInterface) => { | ||
| const moderatedName: string = value.name.replace(/\./g, "_"); | ||
|
|
||
| resolvedInitialValues = { | ||
| ...resolvedInitialValues, | ||
| [moderatedName]: (value.value === "true" || value.value === "false") | ||
| ? JSON.parse(value.value) | ||
| : value.value | ||
| }; | ||
| }); | ||
LinukaAr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| setInitialValues(resolvedInitialValues); | ||
| }, [ originalInitialValues ]); | ||
|
|
||
| /** | ||
| * Prepare form values for submitting. | ||
| * | ||
| * @param values - Form values. | ||
| * @returns Sanitized form values. | ||
| */ | ||
| const getUpdatedConfigurations = (values: TOTPAuthenticatorFormInitialValuesInterface) | ||
| : CommonAuthenticatorFormInitialValuesInterface => { | ||
|
|
||
| const properties: CommonPluggableComponentPropertyInterface[] = []; | ||
|
|
||
| for (const [ name, value ] of Object.entries(values)) { | ||
| if (name !== undefined) { | ||
| const moderatedName: string = name.replace(/_/g, "."); | ||
|
|
||
| properties.push({ | ||
| name: moderatedName, | ||
| value: value.toString() | ||
| }); | ||
LinukaAr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| const result: CommonAuthenticatorFormInitialValuesInterface = { | ||
| ...originalInitialValues, | ||
| properties | ||
| }; | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| return ( | ||
| <Form | ||
| id={ FORM_ID } | ||
| uncontrolledForm={ false } | ||
| onSubmit={ (values: Record<string, any>) => { | ||
| onSubmit(getUpdatedConfigurations(values as TOTPAuthenticatorFormInitialValuesInterface)); | ||
| } } | ||
| initialValues={ initialValues } | ||
| > | ||
| <Field.Checkbox | ||
| ariaLabel="Enable TOTP device progressive enrollment" | ||
| name="TOTP_EnrolUserInAuthenticationFlow" | ||
| label={ | ||
| t("authenticationProvider:forms.authenticatorSettings.totp.enrollUserInAuthenticationFlow.label") | ||
| } | ||
| hint={ | ||
| t("authenticationProvider:forms.authenticatorSettings.totp.enrollUserInAuthenticationFlow.hint") | ||
| } | ||
| readOnly={ readOnly } | ||
| width={ 16 } | ||
| data-testid={ `${ testId }-totp-enrol-user-in-authentication-flow-checkbox` } | ||
| /> | ||
| <Field.Button | ||
| form={ FORM_ID } | ||
| size="small" | ||
| buttonType="primary_btn" | ||
| ariaLabel="TOTP Authenticator update button" | ||
| name="update-button" | ||
| data-testid={ `${ testId }-submit-button` } | ||
| disabled={ isSubmitting } | ||
| loading={ isSubmitting } | ||
| label={ t("common:update") } | ||
| hidden={ readOnly } | ||
| /> | ||
| </Form> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Default props for the component. | ||
| */ | ||
| TOTPAuthenticatorForm.defaultProps = { | ||
| "data-testid": "totp-authenticator-form" | ||
| }; | ||
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
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.