diff --git a/cloud/oauth.py b/cloud/oauth.py index 0b30f06..49249bf 100644 --- a/cloud/oauth.py +++ b/cloud/oauth.py @@ -48,6 +48,14 @@ async def google_login(request: Request): if oauth is None: raise HTTPException(status_code=404, detail="Google login not configured") redirect_uri = str(request.url_for("google_callback")) + # Behind a TLS-terminating reverse proxy the app sees the request as http, so + # url_for builds an http:// redirect_uri — but Google requires the exact + # registered https URI for public hosts (→ redirect_uri_mismatch otherwise). + # Force https except on localhost (where there's no proxy and http is used). + if redirect_uri.startswith("http://") and not any( + h in redirect_uri for h in ("localhost", "127.0.0.1") + ): + redirect_uri = "https://" + redirect_uri[len("http://"):] return await oauth.google.authorize_redirect(request, redirect_uri)