From 7be8ca7be2772bdb00b2131ce8cc020854038dc2 Mon Sep 17 00:00:00 2001 From: aviadl Date: Wed, 1 Jan 2025 22:49:51 +0200 Subject: [PATCH] Impersonate with custom claims And with selected tenant related to https://github.com/descope/etc/issues/8724 + test --- README.md | 2 ++ lib/management/jwt.test.ts | 10 +++++++++- lib/management/jwt.ts | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 19185fc2..b908b1ba 100644 --- a/README.md +++ b/README.md @@ -1076,6 +1076,8 @@ const updatedJWTRes = await descopeClient.management.jwt.impersonate( 'impersonator-id', 'login-id', true, + { k1: 'v1' }, + 't1', ); ``` diff --git a/lib/management/jwt.test.ts b/lib/management/jwt.test.ts index f922266b..0847f3c4 100644 --- a/lib/management/jwt.test.ts +++ b/lib/management/jwt.test.ts @@ -63,11 +63,19 @@ describe('Management JWT', () => { 'imp1', 'imp2', true, + { k1: 'v1' }, + 't1', ); expect(mockHttpClient.post).toHaveBeenCalledWith( apiPaths.jwt.impersonate, - { impersonatorId: 'imp1', loginId: 'imp2', validateConsent: true }, + { + impersonatorId: 'imp1', + loginId: 'imp2', + validateConsent: true, + customClaims: { k1: 'v1' }, + selectedTenant: 't1', + }, { token: 'key' }, ); diff --git a/lib/management/jwt.ts b/lib/management/jwt.ts index b6d348a8..40a3a5df 100644 --- a/lib/management/jwt.ts +++ b/lib/management/jwt.ts @@ -15,11 +15,13 @@ const withJWT = (sdk: CoreSdk, managementKey?: string) => ({ impersonatorId: string, loginId: string, validateConsent: boolean, + customClaims?: Record, + selectedTenant?: string, ): Promise> => transformResponse( sdk.httpClient.post( apiPaths.jwt.impersonate, - { impersonatorId, loginId, validateConsent }, + { impersonatorId, loginId, validateConsent, customClaims, selectedTenant }, { token: managementKey }, ), ),