Skip to content

Commit 05f9e62

Browse files
committed
add third party app patch
add third party app get secret add third party app rotate secret
1 parent f25e2ef commit 05f9e62

File tree

5 files changed

+156
-2
lines changed

5 files changed

+156
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,11 +1227,20 @@ const { id, cleartext: secret } =
12271227
// Update a third party application.
12281228
// Update will override all fields as is. Use carefully.
12291229
await descopeClient.management.thirdPartyApplication.updateApplication({
1230+
id: 'my-app-id',
12301231
name: 'my updated app',
12311232
loginPageUrl: 'http://dummy.com/login',
12321233
approvedCallbackUrls: ['dummy.com', 'myawesomedomain.com'],
12331234
});
12341235

1236+
// Patch a third party application.
1237+
// patch will not override all fields, but update only what given.
1238+
await descopeClient.management.thirdPartyApplication.patchApplication({
1239+
id: 'my-app-id',
1240+
name: 'my updated app name',
1241+
description: 'my new description',
1242+
});
1243+
12351244
// third party application deletion cannot be undone. Use carefully.
12361245
await descopeClient.management.thirdPartyApplication.deleteApplication('my-app-id');
12371246

@@ -1244,6 +1253,16 @@ appsRes.data.forEach((app) => {
12441253
// do something
12451254
});
12461255

1256+
// Get a third party application secret by application id.
1257+
const { cleartext } = await descopeClient.management.thirdPartyApplication.getApplicationSecret(
1258+
'my-app-id',
1259+
);
1260+
1261+
// Rotate a third party application secret by application id.
1262+
const { cleartext } = await descopeClient.management.thirdPartyApplication.rotateApplicationSecret(
1263+
'my-app-id',
1264+
);
1265+
12471266
// Search in all consents. search consents by the given app id and offset to the third page.
12481267
const consentsRes = await descopeClient.management.thirdPartyApplication.searchConsents({
12491268
appId: 'my-app',

lib/management/paths.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ export default {
7979
thirdPartyApplication: {
8080
create: '/v1/mgmt/thirdparty/app/create',
8181
update: '/v1/mgmt/thirdparty/app/update',
82+
patch: '/v1/mgmt/thirdparty/app/patch',
8283
delete: '/v1/mgmt/thirdparty/app/delete',
8384
load: '/v1/mgmt/thirdparty/app/load',
8485
loadAll: '/v1/mgmt/thirdparty/apps/load',
86+
secret: '/v1/mgmt/thirdparty/app/secret',
87+
rotate: '/v1/mgmt/thirdparty/app/rotate',
8588
},
8689
thirdPartyApplicationConsents: {
8790
delete: '/v1/mgmt/thirdparty/consents/delete',

lib/management/thirdpartyapplication.test.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CreateThirdPartyApplicationResponse,
66
ThirdPartyApplication,
77
ThirdPartyApplicationConsent,
8+
ThirdPartyApplicationSecretResponse,
89
} from './types';
910
import { mockCoreSdk, mockHttpClient } from './testutils';
1011

@@ -165,6 +166,47 @@ describe('Management ThirdPartyApplication', () => {
165166
});
166167
});
167168

169+
describe('patchThirdPartyApplication', () => {
170+
it('should send the correct request and receive correct response', async () => {
171+
const httpResponse = {
172+
ok: true,
173+
json: () => {},
174+
clone: () => ({
175+
json: () => Promise.resolve({}),
176+
}),
177+
status: 200,
178+
};
179+
mockHttpClient.post.mockResolvedValue(httpResponse);
180+
181+
const resp = await management.thirdPartyApplication.patchApplication({
182+
id: 'app1',
183+
logo: 'logo',
184+
description: 'desc',
185+
loginPageUrl: 'http://dummy.com',
186+
permissionsScopes: [],
187+
});
188+
189+
expect(mockHttpClient.post).toHaveBeenCalledWith(
190+
apiPaths.thirdPartyApplication.patch,
191+
{
192+
id: 'app1',
193+
permissionsScopes: [],
194+
logo: 'logo',
195+
description: 'desc',
196+
loginPageUrl: 'http://dummy.com',
197+
},
198+
{ token: 'key' },
199+
);
200+
201+
expect(resp).toEqual({
202+
code: 200,
203+
data: {},
204+
ok: true,
205+
response: httpResponse,
206+
});
207+
});
208+
});
209+
168210
describe('deleteThirdPartyApplication', () => {
169211
it('should send the correct request and receive correct response', async () => {
170212
const httpResponse = {
@@ -223,6 +265,70 @@ describe('Management ThirdPartyApplication', () => {
223265
});
224266
});
225267

268+
describe('getThirdPartyApplicationSecret', () => {
269+
it('should send the correct request and receive correct response', async () => {
270+
const httpResponse = {
271+
ok: true,
272+
json: () => {
273+
'1';
274+
},
275+
clone: () => ({
276+
json: () => Promise.resolve({ cleartext: '1' }),
277+
}),
278+
status: 200,
279+
};
280+
mockHttpClient.get.mockResolvedValue(httpResponse);
281+
282+
const resp: SdkResponse<ThirdPartyApplicationSecretResponse> =
283+
await management.thirdPartyApplication.getApplicationSecret(
284+
mockThirdPartyApplications[0].id,
285+
);
286+
287+
expect(mockHttpClient.get).toHaveBeenCalledWith(apiPaths.thirdPartyApplication.secret, {
288+
queryParams: { id: mockThirdPartyApplications[0].id },
289+
token: 'key',
290+
});
291+
292+
expect(resp).toEqual({
293+
code: 200,
294+
data: { cleartext: '1' },
295+
ok: true,
296+
response: httpResponse,
297+
});
298+
});
299+
});
300+
301+
describe('rotateThirdPartyApplication', () => {
302+
it('should send the correct request and receive correct response', async () => {
303+
const httpResponse = {
304+
ok: true,
305+
json: () => {
306+
'1';
307+
},
308+
clone: () => ({
309+
json: () => Promise.resolve({ cleartext: '1' }),
310+
}),
311+
status: 200,
312+
};
313+
mockHttpClient.post.mockResolvedValue(httpResponse);
314+
315+
const resp = await management.thirdPartyApplication.rotateApplicationSecret('app1');
316+
317+
expect(mockHttpClient.post).toHaveBeenCalledWith(
318+
apiPaths.thirdPartyApplication.rotate,
319+
{ id: 'app1' },
320+
{ token: 'key' },
321+
);
322+
323+
expect(resp).toEqual({
324+
code: 200,
325+
data: { cleartext: '1' },
326+
ok: true,
327+
response: httpResponse,
328+
});
329+
});
330+
});
331+
226332
describe('loadAllThirdPartyApplication', () => {
227333
it('should send the correct request and receive correct response', async () => {
228334
const httpResponse = {

lib/management/thirdpartyapplication.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ThirdPartyApplicationConsentSearchOptions,
99
CreateThirdPartyApplicationResponse,
1010
ThirdPartyApplicationOptions,
11+
ThirdPartyApplicationSecretResponse,
1112
} from './types';
1213

1314
type MultipleThirdPartyApplicationResponse = {
@@ -41,6 +42,16 @@ const withThirdPartyApplication = (sdk: CoreSdk, managementKey?: string) => ({
4142
{ token: managementKey },
4243
),
4344
),
45+
patchApplication: (
46+
options: Partial<ThirdPartyApplicationOptions> & { id: string },
47+
): Promise<SdkResponse<never>> =>
48+
transformResponse(
49+
sdk.httpClient.post(
50+
apiPaths.thirdPartyApplication.patch,
51+
{ ...options },
52+
{ token: managementKey },
53+
),
54+
),
4455
deleteApplication: (id: string): Promise<SdkResponse<never>> =>
4556
transformResponse(
4657
sdk.httpClient.post(apiPaths.thirdPartyApplication.delete, { id }, { token: managementKey }),
@@ -60,6 +71,18 @@ const withThirdPartyApplication = (sdk: CoreSdk, managementKey?: string) => ({
6071
}),
6172
(data) => data.apps,
6273
),
74+
getApplicationSecret: (id: string): Promise<SdkResponse<ThirdPartyApplicationSecretResponse>> =>
75+
transformResponse<ThirdPartyApplicationSecretResponse, ThirdPartyApplicationSecretResponse>(
76+
sdk.httpClient.get(apiPaths.thirdPartyApplication.secret, {
77+
queryParams: { id },
78+
token: managementKey,
79+
}),
80+
(data) => data,
81+
),
82+
rotateApplicationSecret: (id: string): Promise<SdkResponse<never>> =>
83+
transformResponse(
84+
sdk.httpClient.post(apiPaths.thirdPartyApplication.rotate, { id }, { token: managementKey }),
85+
),
6386
searchConsents: (
6487
options?: ThirdPartyApplicationConsentSearchOptions,
6588
): Promise<SdkResponse<ThirdPartyApplicationConsent[]>> =>

lib/management/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,14 @@ export type ThirdPartyApplication = ThirdPartyApplicationOptions & {
819819
clientId: string;
820820
};
821821

822-
export type CreateThirdPartyApplicationResponse = {
823-
id: string;
822+
export type ThirdPartyApplicationSecretResponse = {
824823
cleartext: string;
825824
};
826825

826+
export type CreateThirdPartyApplicationResponse = {
827+
id: string;
828+
} & ThirdPartyApplicationSecretResponse;
829+
827830
/**
828831
* Represents a third party application consent for a single application
829832
* for a specific user within the project.

0 commit comments

Comments
 (0)