Skip to content

Commit 69adc6f

Browse files
Larsundsoalmeidxkodiakhq[bot]
authored
feat(OAuth2API): add revokeToken method (#10440)
* feat(OAuth2API): add 'revokeToken' method * Buffer => btoa Co-authored-by: Almeida <[email protected]> * Response is empty, dont return Co-authored-by: Almeida <[email protected]> * Redundant override Co-authored-by: Almeida <[email protected]> * chore: fmt --------- Co-authored-by: Almeida <[email protected]> Co-authored-by: Almeida <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 3d37660 commit 69adc6f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/core/src/api/oauth2.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
type RESTGetAPIOAuth2CurrentApplicationResult,
1414
type RESTPostOAuth2AccessTokenURLEncodedData,
1515
type RESTPostOAuth2AccessTokenResult,
16+
type RESTPostOAuth2TokenRevocationQuery,
17+
type Snowflake,
1618
} from 'discord-api-types/v10';
1719

1820
export class OAuth2API {
@@ -121,4 +123,31 @@ export class OAuth2API {
121123
signal,
122124
}) as Promise<RESTGetAPIOAuth2CurrentAuthorizationResult>;
123125
}
126+
127+
/**
128+
* Revokes an OAuth2 token
129+
*
130+
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-token-revocation-example}
131+
* @param applicationId - The application id
132+
* @param applicationSecret - The application secret
133+
* @param body - The body of the token revocation request
134+
* @param options - The options for the token revocation request
135+
*/
136+
public async revokeToken(
137+
applicationId: Snowflake,
138+
applicationSecret: string,
139+
body: RESTPostOAuth2TokenRevocationQuery,
140+
{ signal }: Pick<RequestData, 'signal'> = {},
141+
) {
142+
await this.rest.post(Routes.oauth2TokenRevocation(), {
143+
body: makeURLSearchParams(body),
144+
passThroughBody: true,
145+
headers: {
146+
Authorization: `Basic ${btoa(`${applicationId}:${applicationSecret}`)}`,
147+
'Content-Type': 'application/x-www-form-urlencoded',
148+
},
149+
auth: false,
150+
signal,
151+
});
152+
}
124153
}

0 commit comments

Comments
 (0)