diff --git a/backend/core/conf.py b/backend/core/conf.py index 8b14a793..7271ebcf 100644 --- a/backend/core/conf.py +++ b/backend/core/conf.py @@ -228,6 +228,7 @@ class Settings(BaseSettings): OAUTH2_LINUX_DO_CLIENT_SECRET: str # 基础配置 + OAUTH2_BACKEND_BASE_URL: str = 'http://127.0.0.1:8000' OAUTH2_FRONTEND_REDIRECT_URI: str = 'http://localhost:5173/oauth2/callback' ################################################## diff --git a/backend/plugin/oauth2/api/v1/github.py b/backend/plugin/oauth2/api/v1/github.py index 06f3466b..0456931e 100644 --- a/backend/plugin/oauth2/api/v1/github.py +++ b/backend/plugin/oauth2/api/v1/github.py @@ -18,7 +18,9 @@ github_client = GitHubOAuth20(settings.OAUTH2_GITHUB_CLIENT_ID, settings.OAUTH2_ @router.get('', summary='获取 Github 授权链接') async def get_github_oauth2_url(request: Request) -> ResponseSchemaModel[str]: - auth_url = await github_client.get_authorization_url(redirect_uri=f'{request.url}/callback') + auth_url = await github_client.get_authorization_url( + redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback' + ) return response_base.success(data=auth_url) diff --git a/backend/plugin/oauth2/api/v1/google.py b/backend/plugin/oauth2/api/v1/google.py index 2be4f268..5d302f2a 100644 --- a/backend/plugin/oauth2/api/v1/google.py +++ b/backend/plugin/oauth2/api/v1/google.py @@ -18,7 +18,9 @@ google_client = GoogleOAuth20(settings.OAUTH2_GOOGLE_CLIENT_ID, settings.OAUTH2_ @router.get('', summary='获取 google 授权链接') async def get_google_oauth2_url(request: Request) -> ResponseSchemaModel[str]: - auth_url = await google_client.get_authorization_url(redirect_uri=f'{request.url}/callback') + auth_url = await google_client.get_authorization_url( + redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback' + ) return response_base.success(data=auth_url) diff --git a/backend/plugin/oauth2/api/v1/linux_do.py b/backend/plugin/oauth2/api/v1/linux_do.py index 627a5ec2..0c3e9a8b 100644 --- a/backend/plugin/oauth2/api/v1/linux_do.py +++ b/backend/plugin/oauth2/api/v1/linux_do.py @@ -18,7 +18,9 @@ linux_do_client = LinuxDoOAuth20(settings.OAUTH2_LINUX_DO_CLIENT_ID, settings.OA @router.get('', summary='获取 LinuxDo 授权链接') async def get_linux_do_oauth2_url(request: Request) -> ResponseSchemaModel[str]: - auth_url = await linux_do_client.get_authorization_url(redirect_uri=f'{request.url}/callback') + auth_url = await linux_do_client.get_authorization_url( + redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback' + ) return response_base.success(data=auth_url) diff --git a/backend/plugin/oauth2/plugin.toml b/backend/plugin/oauth2/plugin.toml index 60818669..64c7126f 100644 --- a/backend/plugin/oauth2/plugin.toml +++ b/backend/plugin/oauth2/plugin.toml @@ -1,6 +1,6 @@ [plugin] summary = 'OAuth 2.0' -version = '0.0.5' +version = '0.0.6' description = '通过 OAuth 2.0 的方式登录系统' author = 'wu-clan'