0
Delete an app token
One script reply has been approved by the moderators Verified

OAuth application owners can revoke a single token for an OAuth application. You must use Basic Authentication when accessing this endpoint, using the OAuth application's client_id and client_secret as the username and password.

Created by hugo697 276 days ago Viewed 8919 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 276 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Delete an app token
6
 * OAuth application owners can revoke a single token for an OAuth application. You must use [Basic Authentication](https://docs.github.com/rest/overview/other-authentication-methods#basic-authentication) when accessing this endpoint, using the OAuth application's `client_id` and `client_secret` as the username and password.
7
 */
8
export async function main(
9
  auth: Github,
10
  client_id: string,
11
  body: { access_token: string; [k: string]: unknown }
12
) {
13
  const url = new URL(`https://api.github.com/applications/${client_id}/token`);
14

15
  const response = await fetch(url, {
16
    method: "DELETE",
17
    headers: {
18
      "Content-Type": "application/json",
19
      Authorization: "Bearer " + auth.token,
20
    },
21
    body: JSON.stringify(body),
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.text();
28
}
29