diff --git a/packages/core/src/api/oauth2.ts b/packages/core/src/api/oauth2.ts index 0c62400f0496..972b70983f30 100644 --- a/packages/core/src/api/oauth2.ts +++ b/packages/core/src/api/oauth2.ts @@ -13,6 +13,8 @@ import { type RESTGetAPIOAuth2CurrentApplicationResult, type RESTPostOAuth2AccessTokenURLEncodedData, type RESTPostOAuth2AccessTokenResult, + type RESTPostOAuth2TokenRevocationQuery, + type Snowflake, } from 'discord-api-types/v10'; export class OAuth2API { @@ -121,4 +123,31 @@ export class OAuth2API { signal, }) as Promise; } + + /** + * Revokes an OAuth2 token + * + * @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-token-revocation-example} + * @param applicationId - The application id + * @param applicationSecret - The application secret + * @param body - The body of the token revocation request + * @param options - The options for the token revocation request + */ + public async revokeToken( + applicationId: Snowflake, + applicationSecret: string, + body: RESTPostOAuth2TokenRevocationQuery, + { signal }: Pick = {}, + ) { + await this.rest.post(Routes.oauth2TokenRevocation(), { + body: makeURLSearchParams(body), + passThroughBody: true, + headers: { + Authorization: `Basic ${btoa(`${applicationId}:${applicationSecret}`)}`, + 'Content-Type': 'application/x-www-form-urlencoded', + }, + auth: false, + signal, + }); + } }