Skip to content

Commit 145d363

Browse files
authored
feat: access key custom attributes CRU (#645)
+ test related to descope/etc#13177
1 parent fbcc8e1 commit 145d363

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,11 @@ await descopeClient.management.accessKey.create(
968968
123456789, // expiration time
969969
null,
970970
[{ tenantId: 'tenant-ID1', roleNames: ['role-name1'] }],
971+
undefined, // userId
972+
undefined, // customClaims
973+
undefined, // description
974+
undefined, // permittedIps
975+
{ attributeName: 'attributeValue' }, // customAttributes
971976
);
972977

973978
// 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: 21 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
/**
@@ -60,11 +63,24 @@ const withAccessKey = (httpClient: HttpClient) => ({
6063
/**
6164
* Search all access keys
6265
* @param tenantIds Optional tenant ID filter to apply on the search results
66+
* @param boundUserId Optional user ID to which the access key is bound
67+
* @param creatingUser Optional identifier of the user who created the access key
68+
* @param customAttributes Optional custom attributes filter to apply on the search results
6369
* @returns An array of found access keys
6470
*/
65-
searchAll: (tenantIds?: string[]): Promise<SdkResponse<AccessKey[]>> =>
71+
searchAll: (
72+
tenantIds?: string[],
73+
boundUserId?: string,
74+
creatingUser?: string,
75+
customAttributes?: Record<string, any>,
76+
): Promise<SdkResponse<AccessKey[]>> =>
6677
transformResponse<MultipleKeysResponse, AccessKey[]>(
67-
httpClient.post(apiPaths.accessKey.search, { tenantIds }),
78+
httpClient.post(apiPaths.accessKey.search, {
79+
tenantIds,
80+
boundUserId,
81+
creatingUser,
82+
customAttributes,
83+
}),
6884
(data) => data.keys,
6985
),
7086
/**
@@ -76,6 +92,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
7692
* @param tenants Optional associated tenants for this key and its roles for each.
7793
* @param customClaims Optional map of claims and their values that will be present in the JWT.
7894
* @param permittedIps Optional list of IP addresses or CIDR ranges that are allowed to use this access key.
95+
* @param customAttributes Optional map of custom attributes and their values to associate with this access key.
7996
* @returns The updated access key
8097
*/
8198
update: (
@@ -86,6 +103,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
86103
tenants?: AssociatedTenant[],
87104
customClaims?: Record<string, any>,
88105
permittedIps?: string[],
106+
customAttributes?: Record<string, any>,
89107
): Promise<SdkResponse<AccessKey>> =>
90108
transformResponse<SingleKeyResponse, AccessKey>(
91109
httpClient.post(apiPaths.accessKey.update, {
@@ -96,6 +114,7 @@ const withAccessKey = (httpClient: HttpClient) => ({
96114
keyTenants: tenants,
97115
customClaims,
98116
permittedIps,
117+
customAttributes,
99118
}),
100119
(data) => data.key,
101120
),

0 commit comments

Comments
 (0)