Skip to content

Commit 3e670c5

Browse files
committed
feat: access key custom attributes CRU
+ test related to descope/etc#13177
1 parent fbcc8e1 commit 3e670c5

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ await descopeClient.management.accessKey.create(
968968
123456789, // expiration time
969969
null,
970970
[{ tenantId: 'tenant-ID1', roleNames: ['role-name1'] }],
971+
{ attributeName: 'attributeValue' },
971972
);
972973

973974
// Load specific user

lib/management/accesskey.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('Management Access Keys', () => {
5151
{ k1: 'v1' },
5252
'hey',
5353
['10.0.0.1', '192.168.1.0/24'],
54+
{ customAttr1: 'value1' },
5455
);
5556

5657
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.accessKey.create, {
@@ -62,6 +63,7 @@ describe('Management Access Keys', () => {
6263
customClaims: { k1: 'v1' },
6364
description: 'hey',
6465
permittedIps: ['10.0.0.1', '192.168.1.0/24'],
66+
customAttributes: { customAttr1: 'value1' },
6567
});
6668

6769
expect(resp).toEqual({
@@ -112,10 +114,18 @@ describe('Management Access Keys', () => {
112114
};
113115
mockHttpClient.post.mockResolvedValue(httpResponse);
114116

115-
const resp: SdkResponse<AccessKey[]> = await management.accessKey.searchAll(['t1']);
117+
const resp: SdkResponse<AccessKey[]> = await management.accessKey.searchAll(
118+
['t1'],
119+
'buid',
120+
'cuser',
121+
{ customAttr1: 'value1' },
122+
);
116123

117124
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.accessKey.search, {
118125
tenantIds: ['t1'],
126+
boundUserId: 'buid',
127+
creatingUser: 'cuser',
128+
customAttributes: { customAttr1: 'value1' },
119129
});
120130

121131
expect(resp).toEqual({
@@ -147,6 +157,7 @@ describe('Management Access Keys', () => {
147157
undefined,
148158
{ k1: 'v1' },
149159
['1.2.3.4'],
160+
{ customAttr1: 'value1' },
150161
);
151162

152163
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.accessKey.update, {
@@ -157,6 +168,7 @@ describe('Management Access Keys', () => {
157168
keyTenants: undefined,
158169
customClaims: { k1: 'v1' },
159170
permittedIps: ['1.2.3.4'],
171+
customAttributes: { customAttr1: 'value1' },
160172
});
161173

162174
expect(resp).toEqual({

lib/management/accesskey.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
2121
* @param customClaims Optional map of claims and their values that will be present in the JWT.
2222
* @param description Optional free text description
2323
* @param permittedIps Optional list of IP addresses or CIDR ranges that are allowed to use this access key.
24+
* @param customAttributes Optional map of custom attributes and their values to associate with this access key.
2425
* @returns A newly created key and its cleartext. Make sure to save the cleartext securely.
2526
*/
2627
create: (
@@ -32,6 +33,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
3233
customClaims?: Record<string, any>,
3334
description?: string,
3435
permittedIps?: string[],
36+
customAttributes?: Record<string, any>,
3537
): Promise<SdkResponse<CreatedAccessKeyResponse>> =>
3638
transformResponse(
3739
httpClient.post(apiPaths.accessKey.create, {
@@ -43,6 +45,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
4345
customClaims,
4446
description,
4547
permittedIps,
48+
customAttributes,
4649
}),
4750
),
4851
/**
@@ -62,9 +65,19 @@ const withAccessKey = (httpClient: HttpClient) => ({
6265
* @param tenantIds Optional tenant ID filter to apply on the search results
6366
* @returns An array of found access keys
6467
*/
65-
searchAll: (tenantIds?: string[]): Promise<SdkResponse<AccessKey[]>> =>
68+
searchAll: (
69+
tenantIds?: string[],
70+
boundUserId?: string,
71+
creatingUser?: string,
72+
customAttributes?: Record<string, any>,
73+
): Promise<SdkResponse<AccessKey[]>> =>
6674
transformResponse<MultipleKeysResponse, AccessKey[]>(
67-
httpClient.post(apiPaths.accessKey.search, { tenantIds }),
75+
httpClient.post(apiPaths.accessKey.search, {
76+
tenantIds,
77+
boundUserId,
78+
creatingUser,
79+
customAttributes,
80+
}),
6881
(data) => data.keys,
6982
),
7083
/**
@@ -76,6 +89,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
7689
* @param tenants Optional associated tenants for this key and its roles for each.
7790
* @param customClaims Optional map of claims and their values that will be present in the JWT.
7891
* @param permittedIps Optional list of IP addresses or CIDR ranges that are allowed to use this access key.
92+
* @param customAttributes Optional map of custom attributes and their values to associate with this access key.
7993
* @returns The updated access key
8094
*/
8195
update: (
@@ -86,6 +100,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
86100
tenants?: AssociatedTenant[],
87101
customClaims?: Record<string, any>,
88102
permittedIps?: string[],
103+
customAttributes?: Record<string, any>,
89104
): Promise<SdkResponse<AccessKey>> =>
90105
transformResponse<SingleKeyResponse, AccessKey>(
91106
httpClient.post(apiPaths.accessKey.update, {
@@ -96,6 +111,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
96111
keyTenants: tenants,
97112
customClaims,
98113
permittedIps,
114+
customAttributes,
99115
}),
100116
(data) => data.key,
101117
),

0 commit comments

Comments
 (0)