Skip to content

Commit

Permalink
feat: Add token.revoke to OAuth client
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Nov 12, 2023
1 parent 65c6578 commit 5929288
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/mastodon/oauth/client.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
}
8 changes: 7 additions & 1 deletion tests/oauth/token.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
});
Expand All @@ -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!,
});
});

0 comments on commit 5929288

Please sign in to comment.