Function
generate_jwt
(
data: dict,
secret: SecretType,
lifetime_seconds: int | None = None,
algorithm: str = JWT_ALGORITHM,
)
Source from the content-addressed store, hash-verified
| 15 | |
| 16 | |
| 17 | def generate_jwt( |
| 18 | data: dict, |
| 19 | secret: SecretType, |
| 20 | lifetime_seconds: int | None = None, |
| 21 | algorithm: str = JWT_ALGORITHM, |
| 22 | ) -> str: |
| 23 | payload = data.copy() |
| 24 | if lifetime_seconds: |
| 25 | expire = datetime.now(timezone.utc) + timedelta(seconds=lifetime_seconds) |
| 26 | payload["exp"] = expire |
| 27 | return jwt.encode(payload, _get_secret_value(secret), algorithm=algorithm) |
| 28 | |
| 29 | |
| 30 | def decode_jwt( |