@@ -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
1820export 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