Skip to content

Security

jwtlib.security

create_access_token

create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str

Generate a new JWT access token.

Parameters:

Name Type Description Default
data dict

Subject data to include in the token payload.

required
expires_delta Optional[timedelta]

Optional expiration override.

None

Returns:

Type Description
str

An encoded JWT string.

get_jwt_payload

get_jwt_payload(token: str) -> TokenPayload

Decode and validate a JWT, returning a strongly-typed payload.

Raises:

Type Description
JWTError

if the token is invalid, expired, or malformed

hash_password

hash_password(password: str) -> str

Hash a plain-text password using the configured crypt context.

Parameters:

Name Type Description Default
password str

The plain-text password to hash.

required

Returns:

Type Description
str

The secure hash string.

verify_password

verify_password(plain_password: str, hashed_password: str) -> bool

Verify a plain-text password against a stored hash.

Parameters:

Name Type Description Default
plain_password str

The unhashed password provided by the user.

required
hashed_password str

The secure hash to verify against.

required

Returns:

Type Description
bool

True if the password is valid, False otherwise.