Repository navigation
Expand file tree
/
Copy pathgithub-callback.html
More file actions
54 lines (51 loc) · 1.77 KB
/
Copy pathgithub-callback.html
File metadata and controls
54 lines (51 loc) · 1.77 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>GitHub Sign-In</title>
<style>html,body{margin:0;width:100%;height:100%;background:#111;color:#eee;font:14px system-ui,sans-serif;display:grid;place-items:center}main{text-align:center;opacity:.8}</style>
</head>
<body>
<main>Completing GitHub sign-in…</main>
<script>
(function(){
const params = new URLSearchParams(location.search);
const payload = {
type: 'github-oauth-callback',
code: params.get('code'),
state: params.get('state'),
error: params.get('error'),
errorDescription: params.get('error_description') || ''
};
if (window.opener && window.opener !== window) {
try {
window.opener.postMessage(payload, location.origin);
} catch (_) {}
setTimeout(() => window.close(), 100);
return;
}
// Popup blockers can force the original window to navigate through OAuth.
// Return to the editor URL recorded by github.js and preserve the callback.
let returnUri = '';
try {
const pending = JSON.parse(localStorage.getItem('editor.github.oauth.pending') || 'null');
returnUri = String(pending?.returnUri || '');
} catch (_) {}
try {
const target = new URL(returnUri || location.href);
if (target.origin !== location.origin) throw new Error('invalid callback target');
target.search = '';
target.hash = '';
for (const key of ['code','state','error','error_description']) {
const value = params.get(key);
if (value) target.searchParams.set(key, value);
}
location.replace(target.href);
} catch (_) {
document.querySelector('main').textContent = 'GitHub sign-in completed. Return to the editor to continue.';
}
})();
</script>
</body>
</html>