Skip to content

Commit 47688e0

Browse files
committed
feat: Add token.revoke to OAuth client
1 parent 65c6578 commit 47688e0

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/mastodon/oauth/client.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
import { type HttpMetaParams } from "../../interfaces";
12
import { type TokenRepository } from "./token-repository";
23

4+
export interface RevokeTokenParams {
5+
/** The client ID, obtained during app registration. */
6+
readonly clientId: string;
7+
/** The client secret, obtained during app registration. */
8+
readonly clientSecret: string;
9+
/** The previously obtained token, to be invalidated. */
10+
readonly token: string;
11+
}
12+
313
export interface Client {
414
readonly token: TokenRepository;
15+
16+
/**
17+
* Revoke an access token to make it no longer valid for use.
18+
* @param params Form data parameters
19+
* @param meta HTTP metadata
20+
* @see https://docs.joinmastodon.org/methods/oauth/#revoke
21+
*/
22+
revoke(
23+
params: RevokeTokenParams,
24+
meta?: HttpMetaParams<"multipart-form">,
25+
): Promise<void>;
526
}

tests/oauth/token.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
import { createOAuthAPIClient } from "../../src";
33

4-
it("issues token", async () => {
4+
it("issues and revokes token", async () => {
55
const oauth = createOAuthAPIClient({
66
url: globalThis.__misc__.url,
77
});
@@ -12,8 +12,14 @@ it("issues token", async () => {
1212
clientSecret: global.__misc__.app.clientSecret!,
1313
username: "admin@localhost",
1414
password: "mastodonadmin",
15-
scope: "read write follow push admin:read admin:write",
15+
scope: "read",
1616
});
1717

1818
expect(token).toHaveProperty("accessToken");
19+
20+
await oauth.revoke({
21+
clientId: global.__misc__.app.clientId!,
22+
clientSecret: global.__misc__.app.clientSecret!,
23+
token: token.accessToken!,
24+
});
1925
});

0 commit comments

Comments
 (0)