feat(qr): add 3-second dynamic QR auto-rotation and global settings configuration (v3.8.46)
This commit is contained in:
@@ -32,12 +32,19 @@ class QRSecurityService:
|
||||
return getattr(Config, 'SECRET_KEY', 'unicaba-secret-qr-key')
|
||||
|
||||
@classmethod
|
||||
def generate_qr_token(cls, user: User, hours_valid: int = DEFAULT_VALID_HOURS) -> str:
|
||||
def generate_qr_token(
|
||||
cls,
|
||||
user: User,
|
||||
hours_valid: int = DEFAULT_VALID_HOURS,
|
||||
valid_seconds: Optional[int] = None
|
||||
) -> str:
|
||||
"""
|
||||
Emite un token JWT firmado de credencial institucional para el usuario.
|
||||
Contiene identificación, rol, DNI y tiempo de expiración.
|
||||
Soporta valid_seconds para tokens dinámicos rotativos anti-captura.
|
||||
"""
|
||||
now = datetime.now(timezone.utc)
|
||||
exp_delta = timedelta(seconds=valid_seconds) if valid_seconds is not None else timedelta(hours=hours_valid)
|
||||
payload = {
|
||||
"sub": str(user.id),
|
||||
"dni": user.document_number or "",
|
||||
@@ -46,7 +53,7 @@ class QRSecurityService:
|
||||
"type": cls.QR_TOKEN_TYPE,
|
||||
"jti": str(uuid.uuid4())[:8],
|
||||
"iat": now,
|
||||
"exp": now + timedelta(hours=hours_valid)
|
||||
"exp": now + exp_delta
|
||||
}
|
||||
return jwt.encode(payload, cls._get_secret(), algorithm="HS256")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user