Skip to content

Commit b83a041

Browse files
jonasnevesclaude
andcommitted
Migrate GitHub OAuth to neevs.io/auth/ callback pattern
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4446651 commit b83a041

3 files changed

Lines changed: 18 additions & 84 deletions

File tree

countries/index.html

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,6 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${c.flag} ${c.name}</h2>
17461746

17471747
const LOCAL_PROXY_URL = 'http://127.0.0.1:7337/claude';
17481748
const GITHUB_CLIENT_ID = 'Ov23lioKDt8Os7hdiSEh';
1749-
const CORS_PROXY_URL = 'https://cors-proxy.jonasneves.workers.dev';
17501749
const OAUTH_CALLBACK_ORIGIN = 'https://neevs.io';
17511750
const GITHUB_API_URL = 'https://models.github.ai/inference/chat/completions';
17521751

@@ -1906,28 +1905,8 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${c.flag} ${c.name}</h2>
19061905

19071906
/* ── GitHub OAuth ── */
19081907

1909-
async function exchangeGitHubToken(code, redirectUri) {
1910-
const res = await fetch(`${CORS_PROXY_URL}/token`, {
1911-
method: 'POST',
1912-
headers: { 'content-type': 'application/json' },
1913-
body: JSON.stringify({ client_id: GITHUB_CLIENT_ID, code, redirect_uri: redirectUri }),
1914-
});
1915-
const data = await res.json();
1916-
if (data.error || !data.access_token) {
1917-
throw new Error(data.error_description || data.error || 'Token exchange failed');
1918-
}
1919-
let username = data.username;
1920-
if (!username) {
1921-
const userRes = await fetch('https://api.github.com/user', {
1922-
headers: { Authorization: `Bearer ${data.access_token}`, Accept: 'application/vnd.github+json' },
1923-
});
1924-
if (userRes.ok) username = (await userRes.json()).login;
1925-
}
1926-
return { token: data.access_token, username: username || '' };
1927-
}
1928-
19291908
async function connectGitHub() {
1930-
const redirectUri = OAUTH_CALLBACK_ORIGIN + '/';
1909+
const redirectUri = OAUTH_CALLBACK_ORIGIN + '/auth/';
19311910
const authUrl = new URL('https://github.com/login/oauth/authorize');
19321911
authUrl.searchParams.set('client_id', GITHUB_CLIENT_ID);
19331912
authUrl.searchParams.set('redirect_uri', redirectUri);
@@ -1945,15 +1924,14 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${c.flag} ${c.name}</h2>
19451924
);
19461925
if (!popup) { reject(new Error('Popup blocked — allow popups for this site')); return; }
19471926

1948-
const handleMessage = async (event) => {
1927+
const handleMessage = (event) => {
19491928
if (event.origin !== OAUTH_CALLBACK_ORIGIN) return;
1950-
const { type, code, error } = event.data || {};
1951-
if (type !== 'oauth-callback') return;
1929+
const { type, auth } = event.data || {};
1930+
if (type !== 'gh-auth') return;
19521931
window.removeEventListener('message', handleMessage);
19531932
clearInterval(pollTimer);
1954-
if (error) { reject(new Error(error)); return; }
1955-
if (!code) { reject(new Error('No code received')); return; }
1956-
try { resolve(await exchangeGitHubToken(code, redirectUri)); } catch (err) { reject(err); }
1933+
if (!auth) { reject(new Error('Authentication failed')); return; }
1934+
resolve({ token: auth.token, username: auth.login });
19571935
};
19581936

19591937
window.addEventListener('message', handleMessage);

earthquakes/index.html

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,6 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${q.place}</h2>
18021802

18031803
const LOCAL_PROXY_URL = 'http://127.0.0.1:7337/claude';
18041804
const GITHUB_CLIENT_ID = 'Ov23lioKDt8Os7hdiSEh';
1805-
const CORS_PROXY_URL = 'https://cors-proxy.jonasneves.workers.dev';
18061805
const OAUTH_CALLBACK_ORIGIN = 'https://neevs.io';
18071806
const GITHUB_API_URL = 'https://models.github.ai/inference/chat/completions';
18081807

@@ -1962,28 +1961,8 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${q.place}</h2>
19621961

19631962
/* ── GitHub OAuth ── */
19641963

1965-
async function exchangeGitHubToken(code, redirectUri) {
1966-
const res = await fetch(`${CORS_PROXY_URL}/token`, {
1967-
method: 'POST',
1968-
headers: { 'content-type': 'application/json' },
1969-
body: JSON.stringify({ client_id: GITHUB_CLIENT_ID, code, redirect_uri: redirectUri }),
1970-
});
1971-
const data = await res.json();
1972-
if (data.error || !data.access_token) {
1973-
throw new Error(data.error_description || data.error || 'Token exchange failed');
1974-
}
1975-
let username = data.username;
1976-
if (!username) {
1977-
const userRes = await fetch('https://api.github.com/user', {
1978-
headers: { Authorization: `Bearer ${data.access_token}`, Accept: 'application/vnd.github+json' },
1979-
});
1980-
if (userRes.ok) username = (await userRes.json()).login;
1981-
}
1982-
return { token: data.access_token, username: username || '' };
1983-
}
1984-
19851964
async function connectGitHub() {
1986-
const redirectUri = OAUTH_CALLBACK_ORIGIN + '/';
1965+
const redirectUri = OAUTH_CALLBACK_ORIGIN + '/auth/';
19871966
const authUrl = new URL('https://github.com/login/oauth/authorize');
19881967
authUrl.searchParams.set('client_id', GITHUB_CLIENT_ID);
19891968
authUrl.searchParams.set('redirect_uri', redirectUri);
@@ -2001,15 +1980,14 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${q.place}</h2>
20011980
);
20021981
if (!popup) { reject(new Error('Popup blocked — allow popups for this site')); return; }
20031982

2004-
const handleMessage = async (event) => {
1983+
const handleMessage = (event) => {
20051984
if (event.origin !== OAUTH_CALLBACK_ORIGIN) return;
2006-
const { type, code, error } = event.data || {};
2007-
if (type !== 'oauth-callback') return;
1985+
const { type, auth } = event.data || {};
1986+
if (type !== 'gh-auth') return;
20081987
window.removeEventListener('message', handleMessage);
20091988
clearInterval(pollTimer);
2010-
if (error) { reject(new Error(error)); return; }
2011-
if (!code) { reject(new Error('No code received')); return; }
2012-
try { resolve(await exchangeGitHubToken(code, redirectUri)); } catch (err) { reject(err); }
1989+
if (!auth) { reject(new Error('Authentication failed')); return; }
1990+
resolve({ token: auth.token, username: auth.login });
20131991
};
20141992

20151993
window.addEventListener('message', handleMessage);

hospital-risk-explorer/index.html

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,6 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${h.name}</h2>
19791979

19801980
const LOCAL_PROXY_URL = 'http://127.0.0.1:7337/claude';
19811981
const GITHUB_CLIENT_ID = 'Ov23lioKDt8Os7hdiSEh';
1982-
const CORS_PROXY_URL = 'https://cors-proxy.jonasneves.workers.dev';
19831982
const OAUTH_CALLBACK_ORIGIN = 'https://neevs.io';
19841983
const GITHUB_API_URL = 'https://models.github.ai/inference/chat/completions';
19851984

@@ -2145,28 +2144,8 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${h.name}</h2>
21452144

21462145
/* ── GitHub OAuth ── */
21472146

2148-
async function exchangeGitHubToken(code, redirectUri) {
2149-
const res = await fetch(`${CORS_PROXY_URL}/token`, {
2150-
method: 'POST',
2151-
headers: { 'content-type': 'application/json' },
2152-
body: JSON.stringify({ client_id: GITHUB_CLIENT_ID, code, redirect_uri: redirectUri }),
2153-
});
2154-
const data = await res.json();
2155-
if (data.error || !data.access_token) {
2156-
throw new Error(data.error_description || data.error || 'Token exchange failed');
2157-
}
2158-
let username = data.username;
2159-
if (!username) {
2160-
const userRes = await fetch('https://api.github.com/user', {
2161-
headers: { Authorization: `Bearer ${data.access_token}`, Accept: 'application/vnd.github+json' },
2162-
});
2163-
if (userRes.ok) username = (await userRes.json()).login;
2164-
}
2165-
return { token: data.access_token, username: username || '' };
2166-
}
2167-
21682147
async function connectGitHub() {
2169-
const redirectUri = OAUTH_CALLBACK_ORIGIN + '/';
2148+
const redirectUri = OAUTH_CALLBACK_ORIGIN + '/auth/';
21702149
const authUrl = new URL('https://github.com/login/oauth/authorize');
21712150
authUrl.searchParams.set('client_id', GITHUB_CLIENT_ID);
21722151
authUrl.searchParams.set('redirect_uri', redirectUri);
@@ -2184,15 +2163,14 @@ <h2>${flag ? '<span class="flag-dot"></span>' : ''}${h.name}</h2>
21842163
);
21852164
if (!popup) { reject(new Error('Popup blocked — allow popups for this site')); return; }
21862165

2187-
const handleMessage = async (event) => {
2166+
const handleMessage = (event) => {
21882167
if (event.origin !== OAUTH_CALLBACK_ORIGIN) return;
2189-
const { type, code, error } = event.data || {};
2190-
if (type !== 'oauth-callback') return;
2168+
const { type, auth } = event.data || {};
2169+
if (type !== 'gh-auth') return;
21912170
window.removeEventListener('message', handleMessage);
21922171
clearInterval(pollTimer);
2193-
if (error) { reject(new Error(error)); return; }
2194-
if (!code) { reject(new Error('No code received')); return; }
2195-
try { resolve(await exchangeGitHubToken(code, redirectUri)); } catch (err) { reject(err); }
2172+
if (!auth) { reject(new Error('Authentication failed')); return; }
2173+
resolve({ token: auth.token, username: auth.login });
21962174
};
21972175

21982176
window.addEventListener('message', handleMessage);

0 commit comments

Comments
 (0)