-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-github-token.html
More file actions
161 lines (141 loc) · 4.68 KB
/
Copy pathtest-github-token.html
File metadata and controls
161 lines (141 loc) · 4.68 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
<title>Test GitHub Token</title>
<style>
body {
font-family: 'Courier New', monospace;
background: #000;
color: #0f0;
padding: 20px;
}
button {
background: #0f0;
color: #000;
border: none;
padding: 10px 20px;
margin: 5px;
cursor: pointer;
font-family: 'Courier New', monospace;
}
button:hover {
background: #0a0;
}
pre {
background: #111;
padding: 10px;
border: 1px solid #0f0;
overflow-x: auto;
}
.success { color: #0f0; }
.error { color: #f00; }
.info { color: #0ff; }
</style>
</head>
<body>
<h1>GitHub Token Test</h1>
<div>
<button onclick="checkToken()">1. Check if Token Exists</button>
<button onclick="getToken()">2. Get Token (Sensitive!)</button>
<button onclick="testGitHubAPI()">3. Test GitHub API</button>
<button onclick="clearOutput()">Clear Output</button>
</div>
<div id="output"></div>
<script>
const output = document.getElementById('output');
function log(message, type = 'info') {
const pre = document.createElement('pre');
pre.className = type;
pre.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
output.appendChild(pre);
}
function clearOutput() {
output.innerHTML = '';
}
async function checkToken() {
try {
if (!window.electronAPI) {
log('ERROR: Not in Electron environment', 'error');
return;
}
const hasToken = await window.electronAPI.hasGitHubToken();
if (hasToken) {
log('✅ GitHub token EXISTS in keychain', 'success');
} else {
log('❌ No GitHub token found', 'error');
log('Please sign in with GitHub to store a token', 'info');
}
} catch (error) {
log(`ERROR: ${error.message}`, 'error');
}
}
async function getToken() {
try {
if (!window.electronAPI) {
log('ERROR: Not in Electron environment', 'error');
return;
}
const token = await window.electronAPI.getGitHubToken();
if (token) {
// Only show first and last 4 characters for security
const masked = token.substring(0, 4) + '...' + token.substring(token.length - 4);
log(`✅ Token retrieved: ${masked}`, 'success');
log(`Token length: ${token.length} characters`, 'info');
log(`Token prefix: ${token.substring(0, 4)}`, 'info');
} else {
log('❌ No token found', 'error');
}
} catch (error) {
log(`ERROR: ${error.message}`, 'error');
}
}
async function testGitHubAPI() {
try {
if (!window.electronAPI) {
log('ERROR: Not in Electron environment', 'error');
return;
}
log('Fetching GitHub token...', 'info');
const token = await window.electronAPI.getGitHubToken();
if (!token) {
log('❌ No GitHub token available', 'error');
return;
}
log('✅ Token retrieved, testing GitHub API...', 'success');
// Test with authenticated request
const response = await fetch('https://api.github.com/user', {
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/vnd.github.v3+json'
}
});
log(`GitHub API Response: ${response.status} ${response.statusText}`, 'info');
if (response.ok) {
const data = await response.json();
log('✅ GitHub API SUCCESS!', 'success');
log(`Authenticated as: ${data.login}`, 'success');
log(`Name: ${data.name}`, 'info');
log(`Public repos: ${data.public_repos}`, 'info');
log(`Rate limit remaining: ${response.headers.get('x-ratelimit-remaining')}/${response.headers.get('x-ratelimit-limit')}`, 'info');
} else {
const errorText = await response.text();
log(`❌ GitHub API Error: ${errorText}`, 'error');
if (response.status === 401) {
log('Token is invalid or expired', 'error');
} else if (response.status === 403) {
log('Rate limit exceeded or insufficient permissions', 'error');
}
}
} catch (error) {
log(`ERROR: ${error.message}`, 'error');
}
}
// Auto-check on load
window.addEventListener('load', () => {
log('GitHub Token Test Page Loaded', 'success');
log('Click buttons above to test token functionality', 'info');
checkToken();
});
</script>
</body>
</html>