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 d21dc5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/mastodon/oauth/token-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token>;

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.token.revoke({
clientId: global.__misc__.app.clientId!,
clientSecret: global.__misc__.app.clientSecret!,
token: token.accessToken!,
});
});

0 comments on commit d21dc5f

Please sign in to comment.