mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
feat(OAuth2API): add revokeToken method (#10440)
* 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>
This commit is contained in:
@@ -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<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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user