Skip to content

Commit 83b6a10

Browse files
downdawndowndawn66
andauthored
Add jwt login whitelist (#204)
Co-authored-by: downdawn <downdawn22@gmail.com>
1 parent d0388b0 commit 83b6a10

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

backend/app/core/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def validator_api_url(cls, values):
9999
TOKEN_URL_SWAGGER: str = f'{API_V1_STR}/auth/swagger_login'
100100
TOKEN_REDIS_PREFIX: str = 'fba_token'
101101
TOKEN_REFRESH_REDIS_PREFIX: str = 'fba_refresh_token'
102+
TOKEN_WHITELIST: list[str] = [ # 白名单
103+
f'{API_V1_STR}/auth/login',
104+
]
102105

103106
# Captcha
104107
CAPTCHA_LOGIN_REDIS_PREFIX: str = 'fba_login_captcha'

backend/app/middleware/jwt_auth_middleware.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from backend.app.common import jwt
1111
from backend.app.common.exception.errors import TokenError
1212
from backend.app.common.log import log
13+
from backend.app.core.conf import settings
1314
from backend.app.database.db_mysql import async_db_session
1415

1516

@@ -35,6 +36,9 @@ async def authenticate(self, request: Request):
3536
if not auth:
3637
return
3738

39+
if request.url.path in settings.TOKEN_WHITELIST:
40+
return
41+
3842
scheme, token = auth.split()
3943
if scheme.lower() != 'bearer':
4044
return

0 commit comments

Comments
 (0)