mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 13:12:24 +00:00
Add jwt login whitelist (#204)
Co-authored-by: downdawn <downdawn22@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user