fix(auth): send an https redirect_uri so GitHub sign-in works

The OAuth app registers https://gh-stats.com/api/auth/github/callback, but
the app was sending the http:// form. GitHub compares redirect_uri to the
registered callback character for character, so it refused every attempt
with "The redirect_uri is not associated with this application" and showed
users a warning that the app might be redirecting them somewhere they were
not expecting. Sign-in has been failing for everyone, and it gates themes,
custom tags and achievements.

_derived_redirect_uri built the URL from X-Forwarded-Proto, falling back to
request.scheme. The cloudflared tunnel does not reliably forward that
header, so the scheme resolved to http. The comment above it claimed the
headers are set, which is what hid this.

Anything that is not localhost or 127.0.0.1 is https. Local dev keeps
working over plain http, pinned by a test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
This commit is contained in:
shay
2026-08-23 09:38:26 -07:00
co-authored by Claude Opus 5
parent 12f6890f57
commit 107273a1c8
2 changed files with 31 additions and 1 deletions
+8 -1
View File
@@ -561,9 +561,16 @@ def auth_github_login():
def _derived_redirect_uri() -> str:
# Works behind cloudflared: the X-Forwarded-Proto/Host headers are set.
# The tunnel does not reliably forward the original scheme, so
# X-Forwarded-Proto can be absent and request.scheme is then http. GitHub
# compares redirect_uri against the callback registered on the OAuth app
# character for character, so an http:// value is rejected with "The
# redirect_uri is not associated with this application" and sign-in becomes
# impossible. Anything that is not a local dev host is served over https.
proto = request.headers.get("X-Forwarded-Proto") or request.scheme
host = request.headers.get("X-Forwarded-Host") or request.host
if host.split(":")[0] not in ("localhost", "127.0.0.1"):
proto = "https"
return f"{proto}://{host}/api/auth/github/callback"