JWT encoding and decoding limited to RS256
Project description
JWTSign
Rust jwt signing bindings for python
Usage:
import time
import json
from jwtsign import PyJwtEncoder, PyJwtDecoder
def read_bin(path: str) -> bytes:
with open(path, "rb") as file:
return file.read()
claims = {
"id": "example",
"exp": int(time.time() + 60),
}
private_key = read_bin("res/private_key.pem")
public_key = read_bin("res/public_key.pem")
encoder = PyJwtEncoder(private_key)
decoder = PyJwtDecoder(public_key, leeway=60)
# Using object encoding
token_claims_obj = encoder.encode_claims_json_obj(claims)
decoded_claims_obj = decoder.decode(token_claims_obj)
# Using serialized object encoding
token_claims_str = encoder.encode_claims_json_str(json.dumps(claims))
decoded_claims_str = decoder.decode(token_claims_str)
Decoder validates expiration time based on UTC with a leeway defined in the PyJwtDecoder::__init__
.
[!NOTE] If at any point you have your claim as serialized JSON keep in mind that this performs slightly faster than the object as encoding parameter, as the rust code uses python bindings to call
json.dumps
on the object.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jwtsign-1.0.8.tar.gz
(3.7 kB
view hashes)
Built Distributions
Close
Hashes for jwtsign-1.0.8-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81ca0792816bf496f761bdaad249c2a729a43f7559d06e9e770e3ffa76268356 |
|
MD5 | f258504fe3c5fea6abcb01e7b0c7ce3c |
|
BLAKE2b-256 | 7799bbb2abb7aaa7c6a5f28b6f5509e3b08541b18373878d42958c35cb896b07 |
Close
Hashes for jwtsign-1.0.8-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 991b312fe51c63a30c46e09c6a12d5038cf25ba79bba235f8047dd1f91b6ac6a |
|
MD5 | ec278c72d0f877468210fc2fcb8e3294 |
|
BLAKE2b-256 | b465191ace98beae0b6da08850c680afebd8fe9170f1611416b041de30be73e6 |
Close
Hashes for jwtsign-1.0.8-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd5a793f6f987f330c16949abbe522c811db02eba514f54a611e89ab603b6c6a |
|
MD5 | 94f7ea3f681826451fbbb7e6f506f3bc |
|
BLAKE2b-256 | b3e0850fc5363963fdf1cd907f38066a9a390fb72fd99b3af874b99e51539236 |
Close
Hashes for jwtsign-1.0.8-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ed9489d1c9822fec691dd30c94ef999c472508be6cadd728a7345b6f7e6457 |
|
MD5 | f6be02ebad5b259bc9e1f67f8710c1ca |
|
BLAKE2b-256 | e94d23afb78497224390cf4e2ef10a84b4242287cedba3688263ff3a2722a9d8 |
Close
Hashes for jwtsign-1.0.8-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a75fd6745835627acda4dbecb7bbb479ef55ec293678605e1b219563107ad5f |
|
MD5 | 2f22baeafbc993d2846a20f4ed32603c |
|
BLAKE2b-256 | 0b41f48a31380123f7687295a19d4e14507e12d670f56081efa8215dd56c2c56 |