diff --git a/backend/app/admin/api/v1/oauth2/github.py b/backend/app/admin/api/v1/oauth2/github.py index 7a054173..28c92037 100644 --- a/backend/app/admin/api/v1/oauth2/github.py +++ b/backend/app/admin/api/v1/oauth2/github.py @@ -13,12 +13,12 @@ router = APIRouter() _github_client = GitHubOAuth20(admin_settings.OAUTH2_GITHUB_CLIENT_ID, admin_settings.OAUTH2_GITHUB_CLIENT_SECRET) -_github_oauth2 = FastAPIOAuth20(_github_client, admin_settings.OAUTH2_GITHUB_REDIRECT_URI) +_github_oauth2 = FastAPIOAuth20(_github_client, redirect_route_name='github_login') @router.get('', summary='获取 Github 授权链接') -async def github_auth2() -> ResponseSchemaModel[str]: - auth_url = await _github_client.get_authorization_url(redirect_uri=admin_settings.OAUTH2_GITHUB_REDIRECT_URI) +async def github_oauth2(request: Request) -> ResponseSchemaModel[str]: + auth_url = await _github_client.get_authorization_url(redirect_uri=f'{request.url}/callback') return response_base.success(data=auth_url) diff --git a/backend/app/admin/api/v1/oauth2/linux_do.py b/backend/app/admin/api/v1/oauth2/linux_do.py index 1b1ee701..6d43fcf4 100644 --- a/backend/app/admin/api/v1/oauth2/linux_do.py +++ b/backend/app/admin/api/v1/oauth2/linux_do.py @@ -16,12 +16,12 @@ admin_settings.OAUTH2_LINUX_DO_CLIENT_ID, admin_settings.OAUTH2_LINUX_DO_CLIENT_SECRET, ) -_linux_do_oauth2 = FastAPIOAuth20(_linux_do_client, admin_settings.OAUTH2_LINUX_DO_REDIRECT_URI) +_linux_do_oauth2 = FastAPIOAuth20(_linux_do_client, redirect_route_name='linux_do_login') @router.get('', summary='获取 LinuxDo 授权链接') -async def linux_do_auth2() -> ResponseSchemaModel[str]: - auth_url = await _linux_do_client.get_authorization_url(redirect_uri=admin_settings.OAUTH2_LINUX_DO_REDIRECT_URI) +async def linux_do_oauth2(request: Request) -> ResponseSchemaModel[str]: + auth_url = await _linux_do_client.get_authorization_url(redirect_uri=f'{request.url}/callback') return response_base.success(data=auth_url) diff --git a/backend/app/admin/conf.py b/backend/app/admin/conf.py index 0b6d7bed..cc41bd11 100644 --- a/backend/app/admin/conf.py +++ b/backend/app/admin/conf.py @@ -19,8 +19,6 @@ class AdminSettings(BaseSettings): OAUTH2_LINUX_DO_CLIENT_SECRET: str # OAuth2 - OAUTH2_GITHUB_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/github/callback' - OAUTH2_LINUX_DO_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/linux-do/callback' OAUTH2_FRONTEND_REDIRECT_URI: str = 'http://localhost:5173/oauth2/callback' # 验证码 diff --git a/pyproject.toml b/pyproject.toml index a0ac6ab3..986d41c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "fast-captcha>=0.3.2", "fastapi-cli==0.0.5", "fastapi-limiter>=0.1.6", - "fastapi-oauth20>=0.0.1a2", + "fastapi-oauth20>=0.0.1", "fastapi-pagination>=0.12.34", "fastapi[standard]==0.115.11", "flower>=2.0.0", diff --git a/requirements.txt b/requirements.txt index 68245cf6..defc31b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,7 +33,7 @@ fast-captcha==0.3.2 fastapi==0.115.11 fastapi-cli==0.0.5 fastapi-limiter==0.1.6 -fastapi-oauth20==0.0.1a2 +fastapi-oauth20==0.0.1 fastapi-pagination==0.12.34 filelock==3.18.0 flower==2.0.1 diff --git a/uv.lock b/uv.lock index 5715c54a..34dfbd8c 100644 --- a/uv.lock +++ b/uv.lock @@ -615,7 +615,7 @@ requires-dist = [ { name = "fastapi", extras = ["standard"], specifier = "==0.115.11" }, { name = "fastapi-cli", specifier = "==0.0.5" }, { name = "fastapi-limiter", specifier = ">=0.1.6" }, - { name = "fastapi-oauth20", specifier = ">=0.0.1a2" }, + { name = "fastapi-oauth20", specifier = ">=0.0.1" }, { name = "fastapi-pagination", specifier = ">=0.12.34" }, { name = "flower", specifier = ">=2.0.0" }, { name = "gevent", specifier = ">=24.11.1" }, @@ -683,15 +683,14 @@ wheels = [ [[package]] name = "fastapi-oauth20" -version = "0.0.1a2" -source = { registry = "https://mirrors.aliyun.com/pypi/simple" } +version = "0.0.1" +source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "fastapi" }, { name = "httpx" }, ] -sdist = { url = "https://mirrors.aliyun.com/pypi/packages/05/24/8a35ecc7d69a3c27372c9ac01127a01c7411897e4eef55804750c7b14f5e/fastapi_oauth20-0.0.1a2.tar.gz", hash = "sha256:516ddd5c631f4efc918d863a26e923318f7b4ada80335666cd42b83a761625a7" } +sdist = { url = "https://files.pythonhosted.org/packages/8e/66/25d4ece161689184f47130bc7ea5bf9c73113c2e628cf586546aa574d8d1/fastapi_oauth20-0.0.1.tar.gz", hash = "sha256:22bf6564f3af42a94cb597f8e20af1366e89e19af49291d15784a4c14059d4c9", size = 6681 } wheels = [ - { url = "https://mirrors.aliyun.com/pypi/packages/13/45/96b1785dbb67a20717933fa02a4713f07743dc621eda75e42988555eb67a/fastapi_oauth20-0.0.1a2-py3-none-any.whl", hash = "sha256:2567ad6129646a775f949e78ec33ea1d14de9db4e63572e2424ba4fdb5b6d18f" }, + { url = "https://files.pythonhosted.org/packages/cf/87/7e0423109ba2c0f8a0794eedff5bb1f79792e5d8d0941ba0b26f962e3e5c/fastapi_oauth20-0.0.1-py3-none-any.whl", hash = "sha256:921fe0e874cb4186998f74b1d951c360400aceb5ca3889a85c806d865a991f88", size = 11242 }, ] [[package]]