diff --git a/backend/app/admin/api/v1/oauth2/github.py b/backend/app/admin/api/v1/oauth2/github.py index 96ef89a1..7293fd78 100644 --- a/backend/app/admin/api/v1/oauth2/github.py +++ b/backend/app/admin/api/v1/oauth2/github.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from fastapi import APIRouter, BackgroundTasks, Depends, Request +from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response from fastapi_limiter.depends import RateLimiter from fastapi_oauth20 import FastAPIOAuth20, GitHubOAuth20 from starlette.responses import RedirectResponse @@ -29,13 +29,17 @@ async def github_auth2() -> ResponseModel: dependencies=[Depends(RateLimiter(times=5, minutes=1))], ) async def github_login( - request: Request, background_tasks: BackgroundTasks, oauth2: FastAPIOAuth20 = Depends(_github_oauth2) + request: Request, + response: Response, + background_tasks: BackgroundTasks, + oauth2: FastAPIOAuth20 = Depends(_github_oauth2), ): token, _state = oauth2 access_token = token['access_token'] user = await _github_client.get_userinfo(access_token) data = await oauth2_service.create_with_login( request=request, + response=response, background_tasks=background_tasks, user=user, social=UserSocialType.github, diff --git a/backend/app/admin/api/v1/oauth2/linux_do.py b/backend/app/admin/api/v1/oauth2/linux_do.py index 8c72a00c..e3961b3b 100644 --- a/backend/app/admin/api/v1/oauth2/linux_do.py +++ b/backend/app/admin/api/v1/oauth2/linux_do.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from fastapi import APIRouter, BackgroundTasks, Depends, Request +from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response from fastapi_limiter.depends import RateLimiter from fastapi_oauth20 import FastAPIOAuth20, LinuxDoOAuth20 from starlette.responses import RedirectResponse @@ -32,13 +32,17 @@ async def linux_do_auth2() -> ResponseModel: dependencies=[Depends(RateLimiter(times=5, minutes=1))], ) async def linux_do_login( - request: Request, background_tasks: BackgroundTasks, oauth2: FastAPIOAuth20 = Depends(_linux_do_oauth2) + request: Request, + response: Response, + background_tasks: BackgroundTasks, + oauth2: FastAPIOAuth20 = Depends(_linux_do_oauth2), ): token, _state = oauth2 access_token = token['access_token'] user = await _linux_do_client.get_userinfo(access_token) data = await oauth2_service.create_with_login( request=request, + response=response, background_tasks=background_tasks, user=user, social=UserSocialType.linuxdo, diff --git a/backend/app/admin/service/oauth2_service.py b/backend/app/admin/service/oauth2_service.py index 55f84cc2..b50089d8 100644 --- a/backend/app/admin/service/oauth2_service.py +++ b/backend/app/admin/service/oauth2_service.py @@ -22,7 +22,12 @@ from backend.utils.timezone import timezone class OAuth2Service: @staticmethod async def create_with_login( - *, request: Request, response: Response, background_tasks: BackgroundTasks, user: dict, social: UserSocialType + *, + request: Request, + response: Response, + background_tasks: BackgroundTasks, + user: dict, + social: UserSocialType, ) -> GetLoginToken | None: async with async_db_session.begin() as db: # 获取 OAuth2 平台用户信息