Initial FastAPI admin auth scaffold
This commit is contained in:
17
app/service/base_token_service.py
Normal file
17
app/service/base_token_service.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from app.constants.result_code import ResultCode
|
||||
from app.exception.err_exception import ErrException
|
||||
from app.lib.jwt.factory import JwtFactory
|
||||
from app.lib.jwt.jwt import Jwt
|
||||
from app.lib.jwt.token import JwtToken
|
||||
|
||||
|
||||
class BaseTokenService:
|
||||
def __init__(self, jwt_factory: JwtFactory) -> None:
|
||||
self.jwt_factory = jwt_factory
|
||||
|
||||
def get_jwt(self, scene: str = "admin") -> Jwt:
|
||||
return self.jwt_factory.get(scene)
|
||||
|
||||
async def check_jwt(self, jwt: Jwt, token: JwtToken) -> None:
|
||||
if await jwt.has_blacklist(token):
|
||||
raise ErrException("token已过期", ResultCode.JWT_EXPIRED)
|
||||
Reference in New Issue
Block a user