From 3b90e04f47e5ac925ecb6f7bc43a898690e6aebf Mon Sep 17 00:00:00 2001 From: simeng-li Date: Mon, 11 Nov 2024 11:32:03 +0800 Subject: [PATCH] feat(core): add unknown session fallback uri field add unknown session fallbacl uri field to the application details page --- .../ApplicationDetailsContent/Settings.tsx | 24 ++++++++++++++++++- .../ApplicationDetailsContent/utils.ts | 5 ++++ .../admin-console/application-details.ts | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/Settings.tsx b/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/Settings.tsx index 880d74a03..ea97dd2ae 100644 --- a/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/Settings.tsx +++ b/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/Settings.tsx @@ -6,6 +6,7 @@ import { Trans, useTranslation } from 'react-i18next'; import FormCard from '@/components/FormCard'; import MultiTextInputField from '@/components/MultiTextInputField'; +import { isDevFeaturesEnabled } from '@/consts/env'; import CodeEditor from '@/ds-components/CodeEditor'; import FormField from '@/ds-components/FormField'; import type { MultiTextInputRule } from '@/ds-components/MultiTextInput/types'; @@ -17,6 +18,7 @@ import TextInput from '@/ds-components/TextInput'; import TextLink from '@/ds-components/TextLink'; import useDocumentationUrl from '@/hooks/use-documentation-url'; import { isJsonObject } from '@/utils/json'; +import { uriValidator } from '@/utils/validator'; import ProtectedAppSettings from './ProtectedAppSettings'; import { type ApplicationForm } from './utils'; @@ -34,10 +36,16 @@ function Settings({ data }: Props) { formState: { errors }, } = useFormContext(); - const { type: applicationType } = data; + const { type: applicationType, isThirdParty } = data; const isNativeApp = applicationType === ApplicationType.Native; const isProtectedApp = applicationType === ApplicationType.Protected; + // TODO: Remove dev features check after the feature is ready for production + const showUnknownSessionFallbackUri = + (applicationType === ApplicationType.Traditional || applicationType === ApplicationType.SPA) && + !isThirdParty && + isDevFeaturesEnabled; + const uriPatternRules: MultiTextInputRule = { pattern: { verify: (value) => !value || validateRedirectUrl(value, isNativeApp ? 'mobile' : 'web'), @@ -164,6 +172,20 @@ function Settings({ data }: Props) { )} /> )} + {showUnknownSessionFallbackUri && ( + + !value || uriValidator(value) || t('errors.invalid_uri_format'), + })} + error={errors.unknownSessionFallbackUri?.message} + placeholder={t('application_details.post_sign_out_redirect_uri_placeholder')} + /> + + )} , 'customDomains'>; // Custom domains are handled separately customData?: string; @@ -33,6 +34,7 @@ export const applicationFormDataParser = { /** Specific metadata for protected apps */ protectedAppMetadata, customData, + unknownSessionFallbackUri, } = data; return { @@ -46,6 +48,7 @@ export const applicationFormDataParser = { ...customClientMetadata, }, customData: JSON.stringify(customData, null, 2), + unknownSessionFallbackUri, isAdmin, } ), @@ -68,6 +71,7 @@ export const applicationFormDataParser = { isAdmin, protectedAppMetadata, customData, + unknownSessionFallbackUri, } = data; return { @@ -90,6 +94,7 @@ export const applicationFormDataParser = { customClientMetadata?.corsAllowedOrigins ), }, + unknownSessionFallbackUri, ...conditional( // Invalid JSON string will be guarded by the form field validation // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment diff --git a/packages/phrases/src/locales/en/translation/admin-console/application-details.ts b/packages/phrases/src/locales/en/translation/admin-console/application-details.ts index b8088d39f..bd92d0142 100644 --- a/packages/phrases/src/locales/en/translation/admin-console/application-details.ts +++ b/packages/phrases/src/locales/en/translation/admin-console/application-details.ts @@ -100,6 +100,9 @@ const application_details = { field_custom_data_tip: 'Additional custom application info not listed in the pre-defined application properties, such as business-specific settings and configurations.', custom_data_invalid: 'Custom data must be a valid JSON object', + field_unknown_session_fallback_uri: 'Unknown session sign-in fallback URI', + field_unknown_session_fallback_uri_tip: + 'The fallback URI when the user accesses the sign-in page without a valid session. User will be redirected to this URI to initiate a new authentication flow.', branding: { name: 'Branding', description: 'Customize your app logo and branding color for the app-level experience.',