11from typing import Annotated
22
3- from fastapi import APIRouter , BackgroundTasks , Depends , Request , Response
3+ from fastapi import APIRouter , BackgroundTasks , Depends , Response
44from fastapi_limiter .depends import RateLimiter
55from fastapi_oauth20 import FastAPIOAuth20 , LinuxDoOAuth20
66from starlette .responses import RedirectResponse
1717
1818
1919@router .get ('' , summary = '获取 LinuxDo 授权链接' )
20- async def get_linux_do_oauth2_url (request : Request ) -> ResponseSchemaModel [str ]:
21- auth_url = await linux_do_client .get_authorization_url (
22- redirect_uri = f'{ settings .OAUTH2_BACKEND_BASE_URL } { request .url .path } /callback'
23- )
20+ async def get_linux_do_oauth2_url () -> ResponseSchemaModel [str ]:
21+ auth_url = await linux_do_client .get_authorization_url (redirect_uri = settings .OAUTH2_LINUX_DO_REDIRECT_URI )
2422 return response_base .success (data = auth_url )
2523
2624
@@ -36,11 +34,11 @@ async def linux_do_oauth2_callback( # noqa: ANN201
3634 background_tasks : BackgroundTasks ,
3735 oauth2 : Annotated [
3836 FastAPIOAuth20 ,
39- Depends (FastAPIOAuth20 (linux_do_client , redirect_route_name = 'linux_do_oauth2_callback' )),
37+ Depends (FastAPIOAuth20 (linux_do_client , redirect_uri = settings . OAUTH2_LINUX_DO_REDIRECT_URI )),
4038 ],
4139):
42- token , _state = oauth2
43- access_token = token ['access_token' ]
40+ token_data , _state = oauth2
41+ access_token = token_data ['access_token' ]
4442 user = await linux_do_client .get_userinfo (access_token )
4543 data = await oauth2_service .create_with_login (
4644 db = db ,
0 commit comments