Skip to content

Commit 1e01ffc

Browse files
authored
Fix the OAuth2 link acquisition in HTTPS (#881)
* Fix the OAuth2 link acquisition in HTTPS * Update OAUTH2_BACKEND_URL to OAUTH2_BACKEND_BASE_URL
1 parent f4b1c43 commit 1e01ffc

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

backend/core/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class Settings(BaseSettings):
228228
OAUTH2_LINUX_DO_CLIENT_SECRET: str
229229

230230
# 基础配置
231+
OAUTH2_BACKEND_BASE_URL: str = 'http://127.0.0.1:8000'
231232
OAUTH2_FRONTEND_REDIRECT_URI: str = 'http://localhost:5173/oauth2/callback'
232233

233234
##################################################

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

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

2426

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

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

2426

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
@router.get('', summary='获取 LinuxDo 授权链接')
2020
async def get_linux_do_oauth2_url(request: Request) -> ResponseSchemaModel[str]:
21-
auth_url = await linux_do_client.get_authorization_url(redirect_uri=f'{request.url}/callback')
21+
auth_url = await linux_do_client.get_authorization_url(
22+
redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback'
23+
)
2224
return response_base.success(data=auth_url)
2325

2426

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.5'
3+
version = '0.0.6'
44
description = '通过 OAuth 2.0 的方式登录系统'
55
author = 'wu-clan'
66

0 commit comments

Comments
 (0)