Skip to content

Commit f46974d

Browse files
authored
Bump fastapi oauth2 from 0.0.1 to 0.0.2 (#896)
1 parent a14d424 commit f46974d

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

backend/core/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ class Settings(BaseSettings):
231231
OAUTH2_LINUX_DO_CLIENT_SECRET: str
232232

233233
# 基础配置
234-
OAUTH2_BACKEND_BASE_URL: str = 'http://127.0.0.1:8000'
234+
OAUTH2_GITHUB_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/github/callback'
235+
OAUTH2_GOOGLE_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/google/callback'
236+
OAUTH2_LINUX_DO_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/linux-do/callback'
235237
OAUTH2_FRONTEND_REDIRECT_URI: str = 'http://localhost:5173/oauth2/callback'
236238

237239
##################################################

backend/plugin/oauth2/api/v1/github.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Annotated
22

3-
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response
3+
from fastapi import APIRouter, BackgroundTasks, Depends, Response
44
from fastapi_limiter.depends import RateLimiter
55
from fastapi_oauth20 import FastAPIOAuth20, GitHubOAuth20
66
from starlette.responses import RedirectResponse
@@ -17,10 +17,8 @@
1717

1818

1919
@router.get('', summary='获取 Github 授权链接')
20-
async def get_github_oauth2_url(request: Request) -> ResponseSchemaModel[str]:
21-
auth_url = await github_client.get_authorization_url(
22-
redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback'
23-
)
20+
async def get_github_oauth2_url() -> ResponseSchemaModel[str]:
21+
auth_url = await github_client.get_authorization_url(redirect_uri=settings.OAUTH2_GITHUB_REDIRECT_URI)
2422
return response_base.success(data=auth_url)
2523

2624

@@ -36,11 +34,11 @@ async def github_oauth2_callback( # noqa: ANN201
3634
background_tasks: BackgroundTasks,
3735
oauth2: Annotated[
3836
FastAPIOAuth20,
39-
Depends(FastAPIOAuth20(github_client, redirect_route_name='github_oauth2_callback')),
37+
Depends(FastAPIOAuth20(github_client, redirect_uri=settings.OAUTH2_GITHUB_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 github_client.get_userinfo(access_token)
4543
data = await oauth2_service.create_with_login(
4644
db=db,

backend/plugin/oauth2/api/v1/google.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Annotated
22

3-
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response
3+
from fastapi import APIRouter, BackgroundTasks, Depends, Response
44
from fastapi_limiter.depends import RateLimiter
55
from fastapi_oauth20 import FastAPIOAuth20, GoogleOAuth20
66
from starlette.responses import RedirectResponse
@@ -17,10 +17,8 @@
1717

1818

1919
@router.get('', summary='获取 google 授权链接')
20-
async def get_google_oauth2_url(request: Request) -> ResponseSchemaModel[str]:
21-
auth_url = await google_client.get_authorization_url(
22-
redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback'
23-
)
20+
async def get_google_oauth2_url() -> ResponseSchemaModel[str]:
21+
auth_url = await google_client.get_authorization_url(redirect_uri=settings.OAUTH2_GOOGLE_REDIRECT_URI)
2422
return response_base.success(data=auth_url)
2523

2624

@@ -36,11 +34,11 @@ async def google_oauth2_callback( # noqa: ANN201
3634
background_tasks: BackgroundTasks,
3735
oauth2: Annotated[
3836
FastAPIOAuth20,
39-
Depends(FastAPIOAuth20(google_client, redirect_route_name='google_oauth2_callback')),
37+
Depends(FastAPIOAuth20(google_client, redirect_uri=settings.OAUTH2_GOOGLE_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 google_client.get_userinfo(access_token)
4543
data = await oauth2_service.create_with_login(
4644
db=db,

backend/plugin/oauth2/api/v1/linux_do.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Annotated
22

3-
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response
3+
from fastapi import APIRouter, BackgroundTasks, Depends, Response
44
from fastapi_limiter.depends import RateLimiter
55
from fastapi_oauth20 import FastAPIOAuth20, LinuxDoOAuth20
66
from starlette.responses import RedirectResponse
@@ -17,10 +17,8 @@
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,

backend/plugin/oauth2/plugin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[plugin]
22
summary = 'OAuth 2.0'
3-
version = '0.0.6'
3+
version = '0.0.7'
44
description = '通过 OAuth 2.0 的方式登录系统'
55
author = 'wu-clan'
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fastapi-oauth20>=0.0.1
1+
fastapi-oauth20>=0.0.2

0 commit comments

Comments
 (0)