Skip to content

Commit c41d12b

Browse files
authored
Add flatten audience flag to client-assertion generation (#587)
1 parent 4dd3e23 commit c41d12b

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ const clientAssertionRes = await descopeClient.management.jwt.generateClientAsse
12341234
'client-id-123', // subject
12351235
['https://example.com/token'], // audience
12361236
300, // expiresIn - number of seconds the token will will be valid for
1237+
false, // Optional. flattenAudience - set the audience claim as one string instead of array of strings (for case only one audience value has given)
12371238
);
12381239
// clientAssertionRes.data.jwt contains the client assertion JWT
12391240
```

lib/management/jwt.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,42 @@ describe('Management JWT', () => {
278278
});
279279
});
280280
});
281+
282+
describe('generateClientAssertionJwtWithFlattenedAudience', () => {
283+
it('should send the correct generateClientAssertionJwt request and receive correct response', async () => {
284+
const httpResponse = {
285+
ok: true,
286+
json: () => mockJWTResponse,
287+
clone: () => ({
288+
json: () => Promise.resolve(mockJWTResponse),
289+
}),
290+
status: 200,
291+
};
292+
mockHttpClient.post.mockResolvedValue(httpResponse);
293+
294+
const resp: SdkResponse<ClientAssertionResponse> =
295+
await management.jwt.generateClientAssertionJwt(
296+
'https://example.com/issuer',
297+
'https://example.com/subject',
298+
['https://example.com/token'],
299+
300,
300+
true,
301+
);
302+
303+
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.jwt.clientAssertion, {
304+
issuer: 'https://example.com/issuer',
305+
subject: 'https://example.com/subject',
306+
audience: ['https://example.com/token'],
307+
expiresIn: 300,
308+
flattenAudience: true,
309+
});
310+
311+
expect(resp).toEqual({
312+
code: 200,
313+
data: mockJWTResponse,
314+
ok: true,
315+
response: httpResponse,
316+
});
317+
});
318+
});
281319
});

lib/management/jwt.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ const withJWT = (httpClient: HttpClient) => ({
7878
subject: string,
7979
audience: string[],
8080
expiresIn: number,
81+
flattenAudience?: boolean,
8182
): Promise<SdkResponse<ClientAssertionResponse>> =>
8283
transformResponse(
83-
httpClient.post(apiPaths.jwt.clientAssertion, { issuer, subject, audience, expiresIn }),
84+
httpClient.post(apiPaths.jwt.clientAssertion, {
85+
issuer,
86+
subject,
87+
audience,
88+
expiresIn,
89+
flattenAudience,
90+
}),
8491
),
8592
});
8693

0 commit comments

Comments
 (0)