Skip to content

Commit

Permalink
feat(OAuth2API): add revokeToken method (#10440)
Browse files Browse the repository at this point in the history
* feat(OAuth2API): add 'revokeToken' method

* Buffer => btoa

Co-authored-by: Almeida <github@almeidx.dev>

* Response is empty, dont return

Co-authored-by: Almeida <github@almeidx.dev>

* Redundant override

Co-authored-by: Almeida <github@almeidx.dev>

* chore: fmt

---------

Co-authored-by: Almeida <github@almeidx.dev>
Co-authored-by: Almeida <almeidx@pm.me>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 20, 2024
1 parent 3d37660 commit 69adc6f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/core/src/api/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
type RESTGetAPIOAuth2CurrentApplicationResult,
type RESTPostOAuth2AccessTokenURLEncodedData,
type RESTPostOAuth2AccessTokenResult,
type RESTPostOAuth2TokenRevocationQuery,
type Snowflake,
} from 'discord-api-types/v10';

export class OAuth2API {
Expand Down Expand Up @@ -121,4 +123,31 @@ export class OAuth2API {
signal,
}) as Promise<RESTGetAPIOAuth2CurrentAuthorizationResult>;
}

/**
* 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<RequestData, 'signal'> = {},
) {
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,
});
}
}

0 comments on commit 69adc6f

Please sign in to comment.