-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathgithub-token-validator-plain.html
More file actions
43 lines (41 loc) · 1.34 KB
/
Copy pathgithub-token-validator-plain.html
File metadata and controls
43 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>GitHub Token Checker</title>
</head>
<body>
<form action="" id="form">
<input type="text" id="token" />
<input type="submit" value="Find" />
<pre id="output">Enter GitHub Token and Press Find.</pre>
</form>
<script>
async function getGitHubUser(token) {
try {
const response = await fetch("https://api.github.com/user", {
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"
}
});
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
const userData = await response.json();
document.getElementById("output").innerHTML = `This token belongs to: ${userData.login}`;
return userData;
} catch (error) {
document.getElementById("output").innerHTML = "Failed to fetch user: " + error.message;
}
}
document.getElementById("form").onsubmit = () => {
const token = document.getElementById("token").value.trim();
getGitHubUser(token);
return false;
};
</script>
</body>
</html>