Update oauth2 route naming and return (#361)

* Update oauth2 route naming and storage

* Update some arg naming

* Update oauth2 redirect uri

* adapts to the front-end oauth2
This commit is contained in:
Wu Clan
2024-07-22 13:47:43 +08:00
committed by GitHub
parent f9c4028c60
commit 581bed2a33
6 changed files with 24 additions and 20 deletions
@@ -1,11 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fastapi import APIRouter
from backend.app.admin.api.v1.auth2.github import router as github_router
from backend.app.admin.api.v1.auth2.linux_do import router as linux_do_router
router = APIRouter(prefix='/auth2')
router.include_router(github_router, prefix='/github', tags=['GitHub OAuth2'])
router.include_router(linux_do_router, prefix='/linuxdo', tags=['Linux Do OAuth2'])
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fastapi import APIRouter
from backend.app.admin.api.v1.oauth2.github import router as github_router
from backend.app.admin.api.v1.oauth2.linux_do import router as linux_do_router
router = APIRouter(prefix='/oauth2')
router.include_router(github_router, prefix='/github', tags=['GitHub OAuth2'])
router.include_router(linux_do_router, prefix='/linux-do', tags=['LinuxDo OAuth2'])
@@ -3,6 +3,7 @@
from fastapi import APIRouter, BackgroundTasks, Depends, Request
from fastapi_limiter.depends import RateLimiter
from fastapi_oauth20 import FastAPIOAuth20, GitHubOAuth20
from starlette.responses import RedirectResponse
from backend.app.admin.conf import admin_settings
from backend.app.admin.service.oauth2_service import oauth2_service
@@ -29,7 +30,7 @@ async def github_auth2() -> ResponseModel:
)
async def github_login(
request: Request, background_tasks: BackgroundTasks, oauth2: FastAPIOAuth20 = Depends(_github_oauth2)
) -> ResponseModel:
):
token, _state = oauth2
access_token = token['access_token']
user = await _github_client.get_userinfo(access_token)
@@ -39,4 +40,4 @@ async def github_login(
user=user,
social=UserSocialType.github,
)
return await response_base.success(data=data)
return RedirectResponse(url=f'{admin_settings.OAUTH2_FRONTEND_REDIRECT_URI}?access_token={data.access_token}')
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fastapi import APIRouter, BackgroundTasks, Depends, Request
from fastapi_limiter.depends import RateLimiter
from fastapi_oauth20 import FastAPIOAuth20, LinuxDoOAuth20
from starlette.responses import RedirectResponse
from backend.app.admin.conf import admin_settings
from backend.app.admin.service.oauth2_service import oauth2_service
@@ -33,7 +33,7 @@ async def linux_do_auth2() -> ResponseModel:
)
async def linux_do_login(
request: Request, background_tasks: BackgroundTasks, oauth2: FastAPIOAuth20 = Depends(_linux_do_oauth2)
) -> ResponseModel:
):
token, _state = oauth2
access_token = token['access_token']
user = await _linux_do_client.get_userinfo(access_token)
@@ -43,4 +43,4 @@ async def linux_do_login(
user=user,
social=UserSocialType.linuxdo,
)
return await response_base.success(data=data)
return RedirectResponse(url=f'{admin_settings.OAUTH2_FRONTEND_REDIRECT_URI}?access_token={data.access_token}')