From 74a70c068d119219e1ff92d9df185b8996c83c76 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Mon, 4 Mar 2024 15:13:50 +0800 Subject: [PATCH] feat(core): add GET /configs/jwt-customizer API --- .../core/src/routes/logto-config.openapi.json | 19 +++++++++++++++++++ packages/core/src/routes/logto-config.test.ts | 9 +++++++++ packages/core/src/routes/logto-config.ts | 12 ++++++++++++ .../integration-tests/src/api/logto-config.ts | 5 +++++ 4 files changed, 45 insertions(+) diff --git a/packages/core/src/routes/logto-config.openapi.json b/packages/core/src/routes/logto-config.openapi.json index 42cec335a..a24d14736 100644 --- a/packages/core/src/routes/logto-config.openapi.json +++ b/packages/core/src/routes/logto-config.openapi.json @@ -168,6 +168,25 @@ "description": "The JWT customizer does not exist." } } + }, + "get": { + "summary": "Get JWT customizer", + "description": "Get the JWT customizer for the given token type.", + "parameters": [ + { + "in": "path", + "name": "tokenType", + "description": "The token type to get the JWT customizer for." + } + ], + "responses": { + "200": { + "description": "The JWT customizer." + }, + "404": { + "description": "The JWT customizer does not exist." + } + } } } } diff --git a/packages/core/src/routes/logto-config.test.ts b/packages/core/src/routes/logto-config.test.ts index 286d7a9b3..9ccc9ad68 100644 --- a/packages/core/src/routes/logto-config.test.ts +++ b/packages/core/src/routes/logto-config.test.ts @@ -275,4 +275,13 @@ describe('configs routes', () => { expect(response.status).toEqual(200); expect(response.body).toEqual(mockJwtCustomizerConfigForAccessToken.value); }); + + it('GET /configs/jwt-customizer/:tokenType should return the record', async () => { + logtoConfigLibraries.getJwtCustomizer.mockResolvedValueOnce( + mockJwtCustomizerConfigForAccessToken + ); + const response = await routeRequester.get('/configs/jwt-customizer/access-token'); + expect(response.status).toEqual(200); + expect(response.body).toEqual(mockJwtCustomizerConfigForAccessToken.value); + }); }); diff --git a/packages/core/src/routes/logto-config.ts b/packages/core/src/routes/logto-config.ts index 413f0d4e9..b4d4ab9ea 100644 --- a/packages/core/src/routes/logto-config.ts +++ b/packages/core/src/routes/logto-config.ts @@ -81,9 +81,21 @@ const getRedactedOidcKeyResponse = async ( export default function logtoConfigRoutes( ...[router, { queries, logtoConfigs, invalidateCache }]: RouterInitArgs ) { +<<<<<<< HEAD const { getAdminConsoleConfig, getRowsByKeys, updateAdminConsoleConfig, updateOidcConfigsByKey } = queries.logtoConfigs; const { getOidcConfigs, upsertJwtCustomizer, getJwtCustomizer } = logtoConfigs; +======= + const { + getAdminConsoleConfig, + getRowsByKeys, + insertJwtCustomizer, + updateAdminConsoleConfig, + updateOidcConfigsByKey, + getJwtCustomizer, + } = queries.logtoConfigs; + const { getOidcConfigs } = logtoConfigs; +>>>>>>> 8086c9bc6 (feat(core): add GET /configs/jwt-customizer API) router.get( '/configs/admin-console', diff --git a/packages/integration-tests/src/api/logto-config.ts b/packages/integration-tests/src/api/logto-config.ts index ed2e869b3..29deba26c 100644 --- a/packages/integration-tests/src/api/logto-config.ts +++ b/packages/integration-tests/src/api/logto-config.ts @@ -45,3 +45,8 @@ export const getJwtCustomizer = async (keyTypePath: 'access-token' | 'client-cre authedAdminApi .get(`configs/jwt-customizer/${keyTypePath}`) .json(); + +export const getJwtCustomizer = async (keyType: LogtoJwtTokenKeyType) => + authedAdminApi + .get(`configs/jwt-customizer/${keyType}`) + .json();