Skip to content

Commit

Permalink
Impersonate with custom claims
Browse files Browse the repository at this point in the history
And with selected tenant
related to descope/etc#8724
+ test
  • Loading branch information
aviadl committed Jan 1, 2025
1 parent 5099c5a commit 7be8ca7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,8 @@ const updatedJWTRes = await descopeClient.management.jwt.impersonate(
'impersonator-id',
'login-id',
true,
{ k1: 'v1' },
't1',
);
```

Expand Down
10 changes: 9 additions & 1 deletion lib/management/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
);

Expand Down
4 changes: 3 additions & 1 deletion lib/management/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ const withJWT = (sdk: CoreSdk, managementKey?: string) => ({
impersonatorId: string,
loginId: string,
validateConsent: boolean,
customClaims?: Record<string, any>,
selectedTenant?: string,
): Promise<SdkResponse<UpdateJWTResponse>> =>
transformResponse(
sdk.httpClient.post(
apiPaths.jwt.impersonate,
{ impersonatorId, loginId, validateConsent },
{ impersonatorId, loginId, validateConsent, customClaims, selectedTenant },
{ token: managementKey },
),
),
Expand Down

0 comments on commit 7be8ca7

Please sign in to comment.