From 69adc6f4b9eb4fafe4a20b01137a270621f1365f Mon Sep 17 00:00:00 2001 From: Lars_und_so <46791248+Larsundso@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:02:53 +0300 Subject: [PATCH] feat(OAuth2API): add `revokeToken` method (#10440) * feat(OAuth2API): add 'revokeToken' method * Buffer => btoa Co-authored-by: Almeida * Response is empty, dont return Co-authored-by: Almeida * Redundant override Co-authored-by: Almeida * chore: fmt --------- Co-authored-by: Almeida Co-authored-by: Almeida Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/core/src/api/oauth2.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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, + }); + } }