-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-github-auth.html
More file actions
143 lines (120 loc) · 4.4 KB
/
Copy pathtest-github-auth.html
File metadata and controls
143 lines (120 loc) · 4.4 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
<!DOCTYPE html>
<html>
<head>
<title>GitHub Device Flow Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: #1a1a1a;
color: #fff;
}
.test-box {
background: #2a2a2a;
padding: 20px;
border-radius: 8px;
margin: 20px 0;
}
button {
background: #e91e63;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background: #c2185b;
}
pre {
background: #1a1a1a;
padding: 15px;
border-radius: 6px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
.success {
color: #4caf50;
}
.error {
color: #f44336;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
background: #1a1a1a;
border: 1px solid #444;
color: #fff;
border-radius: 4px;
font-size: 14px;
}
</style>
</head>
<body>
<h1>GitHub Device Flow Tester</h1>
<div class="test-box">
<h2>Test Your Client ID</h2>
<input type="text" id="clientId" placeholder="Enter your Client ID (e.g., Ov23lidOK9TfEr2LfV4l)"
value="Ov23lidOK9TfEr2LfV4l">
<button onclick="testDeviceFlow()">Test Device Flow</button>
<div id="result"></div>
</div>
<script>
async function testDeviceFlow() {
const clientId = document.getElementById('clientId').value.trim();
const resultDiv = document.getElementById('result');
if (!clientId) {
resultDiv.innerHTML = '<p class="error">Please enter a Client ID</p>';
return;
}
resultDiv.innerHTML = '<p>Testing...</p>';
try {
const params = new URLSearchParams();
params.append('client_id', clientId);
params.append('scope', 'repo user');
const response = await fetch('https://github.com/login/device/code', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: params.toString()
});
const data = await response.json();
let html = `<h3>Response Status: ${response.status} ${response.statusText}</h3>`;
html += `<pre>${JSON.stringify(data, null, 2)}</pre>`;
if (response.ok) {
html += `<p class="success">✅ SUCCESS! Device Flow is working!</p>`;
html += `<p>Device Code: <strong>${data.device_code}</strong></p>`;
html += `<p>User Code: <strong>${data.user_code}</strong></p>`;
html += `<p>Verification URL: <a href="${data.verification_uri}" target="_blank">${data.verification_uri}</a></p>`;
} else {
html += `<p class="error">❌ FAILED</p>`;
html += `<p><strong>Error:</strong> ${data.error || 'Unknown error'}</p>`;
html += `<p><strong>Description:</strong> ${data.error_description || 'No description'}</p>`;
if (response.status === 404) {
html += `<hr><h4>Possible Causes:</h4>`;
html += `<ul>`;
html += `<li>Device Flow is not enabled for this OAuth App</li>`;
html += `<li>The Client ID is incorrect or doesn't exist</li>`;
html += `<li>This is a GitHub App (Iv...) instead of an OAuth App (Ov...)</li>`;
html += `</ul>`;
}
}
resultDiv.innerHTML = html;
} catch (error) {
resultDiv.innerHTML = `<p class="error">❌ Network Error: ${error.message}</p>`;
}
}
// Auto-test on load
window.onload = () => {
testDeviceFlow();
};
</script>
</body>
</html>