From d21dc5f33cf392f5da175e56439611f3029c0100 Mon Sep 17 00:00:00 2001 From: Ryo Igarashi Date: Mon, 13 Nov 2023 03:00:51 +0900 Subject: [PATCH] feat: Add token.revoke to OAuth client --- src/mastodon/oauth/token-repository.ts | 14 ++++++++++++++ tests/oauth/token.spec.ts | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mastodon/oauth/token-repository.ts b/src/mastodon/oauth/token-repository.ts index 9ad2d615e..1d590d600 100644 --- a/src/mastodon/oauth/token-repository.ts +++ b/src/mastodon/oauth/token-repository.ts @@ -12,9 +12,23 @@ export interface CreateTokenParamsWithPassword { export type CreateTokenParams = CreateTokenParamsWithPassword; +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 TokenRepository { create( params: CreateTokenParams, meta?: HttpMetaParams<"multipart-form">, ): Promise; + + revoke( + params: RevokeTokenParams, + meta?: HttpMetaParams<"multipart-form">, + ): Promise; } diff --git a/tests/oauth/token.spec.ts b/tests/oauth/token.spec.ts index 2057f6add..32d534b06 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.token.revoke({ + clientId: global.__misc__.app.clientId!, + clientSecret: global.__misc__.app.clientSecret!, + token: token.accessToken!, + }); });