Add jwt login whitelist (#204)

Co-authored-by: downdawn <downdawn22@gmail.com>
This commit is contained in:
dylan
2023-08-28 15:33:18 +08:00
committed by GitHub
co-authored by downdawn
parent d0388b0256
commit 83b6a10327
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -99,6 +99,9 @@ class Settings(BaseSettings):
TOKEN_URL_SWAGGER: str = f'{API_V1_STR}/auth/swagger_login'
TOKEN_REDIS_PREFIX: str = 'fba_token'
TOKEN_REFRESH_REDIS_PREFIX: str = 'fba_refresh_token'
TOKEN_WHITELIST: list[str] = [ # 白名单
f'{API_V1_STR}/auth/login',
]
# Captcha
CAPTCHA_LOGIN_REDIS_PREFIX: str = 'fba_login_captcha'
@@ -10,6 +10,7 @@ from starlette.responses import JSONResponse
from backend.app.common import jwt
from backend.app.common.exception.errors import TokenError
from backend.app.common.log import log
from backend.app.core.conf import settings
from backend.app.database.db_mysql import async_db_session
@@ -35,6 +36,9 @@ class JwtAuthMiddleware(AuthenticationBackend):
if not auth:
return
if request.url.path in settings.TOKEN_WHITELIST:
return
scheme, token = auth.split()
if scheme.lower() != 'bearer':
return