jwt_helper aims to be a simple to use wrapper around `pyjwt with some predefined functions to make life easier.
The most important classes of this library are
- JWTEncoder - A simple Helper class to create JWTs
- Issuer - A class which holds Informations about an Entity that signs JWTs
- JWTValidator - A simple class containing multiple `Issuer`s which get used to validate JWTs
Here are some Examples to show different Features of the jwt_helper package
from jwt_helper import JWTEncoder, SignMethod
jwt_encoder = JWTEncoder(
issuer="test_issuer", signmethod=SignMethod.HS512, secret="super_secret_hmac_key"
)
jwt = jwt_encoder.create_jwt(
headers={"generic_jwt_header_item": "test123"},
body={"username": "test123"},
valid_minutes=10,
)
from jwt_helper import JWTValidator, Issuer, SignMethod
validator = JWTValidator()
validator.add_issuer(
Issuer(
name="test_issuer",
secret="super_secret_hmac_key",
methods=[SignMethod.HS256, SignMethod.HS384, SignMethod.HS512],
)
)
validator.add_issuer(
Issuer(
name="another_jwt_issuer",
secret="another secret hmac key",
methods=[SignMethod.HS256],
)
)
if not validator.verify_jwt(jwt):
print("JWT is invalid")
jwt_content = validator.get_jwt_as_dict(jwt)