Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OAuth2API): add revokeToken method #10440

Merged
merged 8 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`)}`,
kyranet marked this conversation as resolved.
Show resolved Hide resolved
'Content-Type': 'application/x-www-form-urlencoded',
},
auth: false,
signal,
});
}
}
Loading