Skip to content

Commit e448757

Browse files
authored
chore(backend): Add API keys get, delete and update methods (#7400)
1 parent 8c4ce9c commit e448757

File tree

5 files changed

+466
-5
lines changed

5 files changed

+466
-5
lines changed

.changeset/early-clouds-shake.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@clerk/backend": minor
3+
---
4+
5+
Added API keys `get`, `delete` and `update` methods.
6+
7+
Usage:
8+
9+
```ts
10+
await clerkClient.apiKeys.get('api_key_id')
11+
12+
await clerkClient.apiKeys.update({
13+
apiKeyId: 'api_key_id',
14+
scopes: ['scope1', 'scope2']
15+
})
16+
17+
await clerkClient.apiKeys.delete('api_key_id')
18+
```

integration/testUtils/usersService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export type FakeOrganization = {
6262
export type FakeAPIKey = {
6363
apiKey: APIKey;
6464
secret: string;
65-
revoke: () => Promise<APIKey>;
65+
revoke: (reason?: string | null) => Promise<APIKey>;
6666
};
6767

6868
export type UserService = {
@@ -208,7 +208,8 @@ export const createUserService = (clerkClient: ClerkClient) => {
208208
return {
209209
apiKey,
210210
secret: apiKey.secret ?? '',
211-
revoke: () => clerkClient.apiKeys.revoke({ apiKeyId: apiKey.id, revocationReason: 'For testing purposes' }),
211+
revoke: (reason?: string | null) =>
212+
clerkClient.apiKeys.revoke({ apiKeyId: apiKey.id, revocationReason: reason }),
212213
} satisfies FakeAPIKey;
213214
},
214215
passwordCompromised: async (userId: string) => {

integration/tests/machine-auth/api-keys.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test.describe('Next.js API key auth within clerkMiddleware() @machine', () => {
6565
});
6666

6767
test.afterAll(async () => {
68-
await fakeAPIKey.revoke();
68+
await fakeAPIKey.revoke('Testing purposes within clerkMiddleware()');
6969
await fakeUser.deleteIfExists();
7070
await app.teardown();
7171
});

0 commit comments

Comments
 (0)