diff --git a/src/mastodon/oauth/client.ts b/src/mastodon/oauth/client.ts index 6e1ff5744..3fa415ae4 100644 --- a/src/mastodon/oauth/client.ts +++ b/src/mastodon/oauth/client.ts @@ -1,5 +1,26 @@ +import { type HttpMetaParams } from "../../interfaces"; import { type TokenRepository } from "./token-repository"; +export interface RevokeTokenParams { + /** The client ID, obtained during app registration. */ + readonly clientId: string; + /** The client secret, obtained during app registration. */ + readonly clientSecret: string; + /** The previously obtained token, to be invalidated. */ + readonly token: string; +} + export interface Client { readonly token: TokenRepository; + + /** + * Revoke an access token to make it no longer valid for use. + * @param params Form data parameters + * @param meta HTTP metadata + * @see https://docs.joinmastodon.org/methods/oauth/#revoke + */ + revoke( + params: RevokeTokenParams, + meta?: HttpMetaParams<"multipart-form">, + ): Promise; } diff --git a/tests/oauth/token.spec.ts b/tests/oauth/token.spec.ts index 2057f6add..baf6ce52f 100644 --- a/tests/oauth/token.spec.ts +++ b/tests/oauth/token.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { createOAuthAPIClient } from "../../src"; -it("issues token", async () => { +it("issues and revokes token", async () => { const oauth = createOAuthAPIClient({ url: globalThis.__misc__.url, }); @@ -16,4 +16,10 @@ it("issues token", async () => { }); expect(token).toHaveProperty("accessToken"); + + await oauth.revoke({ + clientId: global.__misc__.app.clientId!, + clientSecret: global.__misc__.app.clientSecret!, + token: token.accessToken!, + }); });