in modular_api/helpers/jwt_auth.py [0:0]
def validate_refresh_token(refresh_token: str) -> tuple:
try:
decoded_token = jwt.decode(
refresh_token,
key=SP.env.secret_key(),
algorithms='HS256',
)
except (jwt.ExpiredSignatureError, jwt.InvalidTokenError, Exception):
return None, None
# Retrieve the token details
username = decoded_token['username']
version = decoded_token['version']
# Check if the token exists and is valid
existing_token = RefreshTokenService.get_refresh_token(username)
if not existing_token:
return None, None
# Retrieve the existing_token from db details
version_from_db = existing_token.version
# Validate if version match the database records
if not version == version_from_db:
RefreshTokenService.delete_refresh_token(existing_token)
return None, None
return username, version