asyncio style refactoring
This commit is contained in:
@@ -31,27 +31,27 @@ class JwtService:
|
||||
|
||||
self.error=Errors()
|
||||
|
||||
def _validate_sub(self,data:dict)->None:
|
||||
async def _validate_sub(self,data:dict)->None:
|
||||
if not (data.get("sub")) or data.get("sub") == "":
|
||||
raise self.error.credentials_error(detail="Jwt token is incorrect")
|
||||
|
||||
def create_access_token(self, data:dict)->str:
|
||||
async def create_access_token(self, data:dict)->str:
|
||||
|
||||
user_info=data.copy()
|
||||
|
||||
self._validate_sub(user_info)
|
||||
await self._validate_sub(user_info)
|
||||
|
||||
user_info.update({"exp": datetime.now(UTC)+timedelta(minutes=env_settings.ACCESS_TOKEN_EXPIRE_MINUTES),
|
||||
"token_type":"access"})
|
||||
return jwt.encode(user_info, env_settings.SECRET_KEY, env_settings.ALGORITHM)
|
||||
|
||||
|
||||
def create_refresh_token(self, data:dict)->tuple[str, str]:
|
||||
async def create_refresh_token(self, data:dict)->tuple[str, str]:
|
||||
|
||||
user_info=data.copy()
|
||||
jti=str(uuid4())
|
||||
|
||||
self._validate_sub(user_info)
|
||||
await self._validate_sub(user_info)
|
||||
|
||||
user_info.update({"exp":datetime.now(UTC)+timedelta(days=env_settings.REFRESH_TOKEN_EXPIRE_DAYS),
|
||||
"token_type":"refresh",
|
||||
@@ -62,7 +62,7 @@ class JwtService:
|
||||
|
||||
|
||||
|
||||
def jwt_decode(self, token:str)->dict:
|
||||
async def jwt_decode(self, token:str)->dict:
|
||||
|
||||
try:
|
||||
payload=jwt.decode(token, env_settings.SECRET_KEY, algorithms=[env_settings.ALGORITHM], options={"require_exp": True} )
|
||||
|
||||
Reference in New Issue
Block a user