From 94c6ca2ba2a8b33a9a3c4d824a4e00395be675ac Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 31 Jul 2026 22:02:04 +0800 Subject: [PATCH] fix: fix GitHub OAuth redirect URI and URL encoding (fixes #821) --- backend/app/services/auth_service.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/app/services/auth_service.py b/backend/app/services/auth_service.py index f84d09d17..3aad6ba05 100644 --- a/backend/app/services/auth_service.py +++ b/backend/app/services/auth_service.py @@ -14,6 +14,7 @@ import logging from datetime import datetime, timezone, timedelta from typing import Optional, Dict +from urllib.parse import urlencode import httpx from jose import jwt, JWTError @@ -31,7 +32,7 @@ GITHUB_CLIENT_ID = os.getenv("GITHUB_CLIENT_ID", "") GITHUB_CLIENT_SECRET = os.getenv("GITHUB_CLIENT_SECRET", "") GITHUB_REDIRECT_URI = os.getenv( - "GITHUB_REDIRECT_URI", "http://localhost:3000/auth/callback" + "GITHUB_REDIRECT_URI", "http://localhost:3000/auth/github/callback" ) JWT_SECRET_KEY = os.getenv("JWT_SECRET_KEY") or secrets.token_urlsafe(32) @@ -164,11 +165,9 @@ def get_github_authorize_url(state: Optional[str] = None) -> tuple: "response_type": "code", } return ( - f"https://github.com/login/oauth/authorize?{'&'.join(f'{k}={v}' for k, v in params.items())}", + f"https://github.com/login/oauth/authorize?{urlencode(params)}", state, ) - - def verify_oauth_state(state: str) -> bool: """Verify the OAuth state parameter is valid.""" if not state: