diff --git a/packages/console/src/containers/ConsoleContent/index.tsx b/packages/console/src/containers/ConsoleContent/index.tsx index 0f0e59207..2d0bb4a49 100644 --- a/packages/console/src/containers/ConsoleContent/index.tsx +++ b/packages/console/src/containers/ConsoleContent/index.tsx @@ -1,3 +1,4 @@ +import { LogtoJwtTokenPath } from '@logto/schemas'; import { useContext } from 'react'; import { Navigate, Route, Routes, useOutletContext } from 'react-router-dom'; @@ -28,7 +29,7 @@ import Dashboard from '@/pages/Dashboard'; import EnterpriseSsoConnectors from '@/pages/EnterpriseSso'; import EnterpriseSsoConnectorDetails from '@/pages/EnterpriseSsoDetails'; import GetStarted from '@/pages/GetStarted'; -import JwtClaims, { JwtTokenType } from '@/pages/JwtClaims'; +import JwtClaims from '@/pages/JwtClaims'; import Mfa from '@/pages/Mfa'; import NotFound from '@/pages/NotFound'; import OrganizationDetails from '@/pages/OrganizationDetails'; @@ -206,14 +207,14 @@ function ConsoleContent() { )} {isDevFeaturesEnabled && ( - } /> + } /> } + path={LogtoJwtTokenPath.AccessToken} + element={} /> } + path={LogtoJwtTokenPath.ClientCredentials} + element={} /> )} diff --git a/packages/console/src/pages/JwtClaims/ScriptSection.tsx b/packages/console/src/pages/JwtClaims/ScriptSection.tsx index e0020a5c0..73680a930 100644 --- a/packages/console/src/pages/JwtClaims/ScriptSection.tsx +++ b/packages/console/src/pages/JwtClaims/ScriptSection.tsx @@ -1,4 +1,5 @@ /* Code Editor for the custom JWT claims script. */ +import { LogtoJwtTokenPath } from '@logto/schemas'; import { useMemo } from 'react'; import { useFormContext, Controller } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; @@ -6,13 +7,13 @@ import { useTranslation } from 'react-i18next'; import Card from '@/ds-components/Card'; import MonacoCodeEditor, { type ModelSettings } from './MonacoCodeEditor'; -import { userJwtFile, machineToMachineJwtFile, JwtTokenType } from './config'; +import { userJwtFile, machineToMachineJwtFile } from './config'; import * as styles from './index.module.scss'; import { type JwtClaimsFormType } from './type'; const titlePhrases = Object.freeze({ - [JwtTokenType.UserAccessToken]: 'user_jwt', - [JwtTokenType.MachineToMachineAccessToken]: 'machine_to_machine_jwt', + [LogtoJwtTokenPath.AccessToken]: 'user_jwt', + [LogtoJwtTokenPath.ClientCredentials]: 'machine_to_machine_jwt', }); function ScriptSection() { @@ -22,7 +23,7 @@ function ScriptSection() { const tokenType = watch('tokenType'); const activeModel = useMemo( - () => (tokenType === JwtTokenType.UserAccessToken ? userJwtFile : machineToMachineJwtFile), + () => (tokenType === LogtoJwtTokenPath.AccessToken ? userJwtFile : machineToMachineJwtFile), [tokenType] ); return ( diff --git a/packages/console/src/pages/JwtClaims/SettingsSection/InstructionTab.tsx b/packages/console/src/pages/JwtClaims/SettingsSection/InstructionTab.tsx index e43111511..e477fbce0 100644 --- a/packages/console/src/pages/JwtClaims/SettingsSection/InstructionTab.tsx +++ b/packages/console/src/pages/JwtClaims/SettingsSection/InstructionTab.tsx @@ -1,3 +1,4 @@ +import { LogtoJwtTokenPath } from '@logto/schemas'; import { Editor } from '@monaco-editor/react'; import classNames from 'classnames'; import { useCallback } from 'react'; @@ -7,7 +8,6 @@ import { useTranslation } from 'react-i18next'; import Table from '@/ds-components/Table'; import { - JwtTokenType, userDataDescription, tokenDataDescription, fetchExternalDataEditorOptions, @@ -55,7 +55,7 @@ function InstructionTab({ isActive }: Props) { return (
{t('jwt_claims.jwt_claims_description')}
- {tokenType === JwtTokenType.UserAccessToken && ( + {tokenType === LogtoJwtTokenPath.AccessToken && ( - tokenType === JwtTokenType.UserAccessToken + tokenType === LogtoJwtTokenPath.AccessToken ? userTokenModelSettings : machineToMachineTokenModelSettings, [tokenType] diff --git a/packages/console/src/pages/JwtClaims/config.tsx b/packages/console/src/pages/JwtClaims/config.tsx index 2cdadc324..da7d1e697 100644 --- a/packages/console/src/pages/JwtClaims/config.tsx +++ b/packages/console/src/pages/JwtClaims/config.tsx @@ -5,14 +5,6 @@ import UserFileIcon from '@/assets/icons/user-file-icon.svg'; import type { ModelSettings } from './MonacoCodeEditor/type.js'; -/** - * JWT token types - */ -export enum JwtTokenType { - UserAccessToken = 'user-access-token', - MachineToMachineAccessToken = 'm2m-access-token', -} - /** * JWT token code editor configuration */ diff --git a/packages/console/src/pages/JwtClaims/index.tsx b/packages/console/src/pages/JwtClaims/index.tsx index aaaefe6ee..2ebe9c1a2 100644 --- a/packages/console/src/pages/JwtClaims/index.tsx +++ b/packages/console/src/pages/JwtClaims/index.tsx @@ -1,4 +1,5 @@ import { withAppInsights } from '@logto/app-insights/react/AppInsightsReact'; +import { LogtoJwtTokenPath } from '@logto/schemas'; import classNames from 'classnames'; import { useMemo } from 'react'; import { useForm, FormProvider } from 'react-hook-form'; @@ -11,21 +12,18 @@ import TabNav, { TabNavItem } from '@/ds-components/TabNav'; import ScriptSection from './ScriptSection'; import SettingsSection from './SettingsSection'; -import { JwtTokenType } from './config'; import * as styles from './index.module.scss'; import { type JwtClaimsFormType } from './type'; -export { JwtTokenType } from './config'; - const tabPhrases = Object.freeze({ - [JwtTokenType.UserAccessToken]: 'user_jwt_tab', - [JwtTokenType.MachineToMachineAccessToken]: 'machine_to_machine_jwt_tab', + [LogtoJwtTokenPath.AccessToken]: 'user_jwt_tab', + [LogtoJwtTokenPath.ClientCredentials]: 'machine_to_machine_jwt_tab', }); -const getPath = (tab: JwtTokenType) => `/jwt-claims/${tab}`; +const getPath = (tab: LogtoJwtTokenPath) => `/jwt-claims/${tab}`; type Props = { - tab: JwtTokenType; + tab: LogtoJwtTokenPath; }; // TODO: API integration @@ -34,21 +32,21 @@ function JwtClaims({ tab }: Props) { const userJwtClaimsForm = useForm({ defaultValues: { - tokenType: JwtTokenType.UserAccessToken, + tokenType: LogtoJwtTokenPath.AccessToken, environmentVariables: [{ key: '', value: '' }], }, }); const machineToMachineJwtClaimsForm = useForm({ defaultValues: { - tokenType: JwtTokenType.MachineToMachineAccessToken, + tokenType: LogtoJwtTokenPath.ClientCredentials, environmentVariables: [{ key: '', value: '' }], }, }); const activeForm = useMemo( () => - tab === JwtTokenType.UserAccessToken ? userJwtClaimsForm : machineToMachineJwtClaimsForm, + tab === LogtoJwtTokenPath.AccessToken ? userJwtClaimsForm : machineToMachineJwtClaimsForm, [machineToMachineJwtClaimsForm, tab, userJwtClaimsForm] ); @@ -70,7 +68,7 @@ function JwtClaims({ tab }: Props) { className={styles.header} /> - {Object.values(JwtTokenType).map((tokenType) => ( + {Object.values(LogtoJwtTokenPath).map((tokenType) => ( {t(`jwt_claims.${tabPhrases[tokenType]}`)} diff --git a/packages/console/src/pages/JwtClaims/type.ts b/packages/console/src/pages/JwtClaims/type.ts index 4d633154a..a4f0aa187 100644 --- a/packages/console/src/pages/JwtClaims/type.ts +++ b/packages/console/src/pages/JwtClaims/type.ts @@ -1,7 +1,7 @@ -import { type JwtTokenType } from './config.js'; +import type { LogtoJwtTokenPath } from '@logto/schemas'; export type JwtClaimsFormType = { - tokenType: JwtTokenType; + tokenType: LogtoJwtTokenPath; script?: string; environmentVariables?: Array<{ key: string; value: string }>; testSample?: { diff --git a/packages/core/src/routes/logto-config.ts b/packages/core/src/routes/logto-config.ts index 335bbc0aa..18c53b635 100644 --- a/packages/core/src/routes/logto-config.ts +++ b/packages/core/src/routes/logto-config.ts @@ -15,6 +15,7 @@ import { jwtCustomizerAccessTokenGuard, jwtCustomizerClientCredentialsGuard, LogtoJwtTokenKey, + LogtoJwtTokenPath, } from '@logto/schemas'; import { z } from 'zod'; @@ -24,11 +25,6 @@ import { exportJWK } from '#src/utils/jwks.js'; import type { AuthedRouter, RouterInitArgs } from './types.js'; -enum LogtoJwtTokenPath { - AccessToken = 'access-token', - ClientCredentials = 'client-credentials', -} - /** * Provide a simple API router key type and DB config key mapping */ diff --git a/packages/schemas/src/types/jwt-customizer.ts b/packages/schemas/src/types/jwt-customizer.ts index ea28c2827..6ceaa4c1a 100644 --- a/packages/schemas/src/types/jwt-customizer.ts +++ b/packages/schemas/src/types/jwt-customizer.ts @@ -54,3 +54,7 @@ export const customJwtFetcherGuard = jwtCustomizerGuard token: jsonObjectGuard, context: jsonObjectGuard.optional(), }); +export enum LogtoJwtTokenPath { + AccessToken = 'access-token', + ClientCredentials = 'client-credentials', +}