Skip to main content

Simple JWT Manager for ES512

Project description

Obsolete!

  • The package is functional, but I've decided not to further develop it.
  • You can use joserfc-wrapper instead.

Simple JWT Manager for ES512

A simple JWT manager with ES512 key management, token generation and validation with options to integrate into your project or use in the cli.

Install

pip install PyJwt512

Usage in CLI

# generate new ES512 private and public key
$ pyjwt512 keys --dir=<path>

# validate a token
$ pyjwt512 check --dir=<path> --aud=<audience> --token=<jwt token>

# get new token
$ pyjwt512 token --dir=<path> --iss=<issuer> --aud=<audince> --uid=<client id>

For example:

$ pyjwt512 keys --dir=/tmp
New keys has been saved in /tmp/001581e99ba047bca44871c4248f689c-public.pem and /tmp/001581e99ba047bca44871c4248f689c.pem files.
$ pyjwt512 token --dir=/tmp --iss=https://example.com --aud=service.example.com --uid=1234
Token:  eyJhbGciOiJF...
$ pyjwt512 check --dir=/tmp --aud=service.example.com --token=eyJhbGciOiJF...
Token is valid.
iss : https://example.com, aud : service.example.com, iat : 1704896624, uid : 1234, kid : 001581e99ba047bca44871c4248f689c

Print help:

$ pyjwt512
$ pyjwt512 keys --help
$ pyjwt512 token --help
$ pyjwt512 check --help

Usage in a script

import os
from pyjwt512 import Es512KeysManger

# Create new keys
es512 = Es512KeysManger()
es512.generate_new_keys()

cert_dir = "/tmp"

if not es512.save_new_keys(cert_dir=cert_dir):
    print(f"Error generating keys")

k_priv = os.path.join(cert_dir, f"{es512.get_root_filename()}.pem")
k_pub = os.path.join(cert_dir, f"{es512.get_root_filename()}-public.pem")

print(f"New keys has been saved in {k_pub} and {k_priv} file.")
from pyjwt512 import CreateTokenException
from pyjwt512 import CreateJwtToken

# Create new token
payload = {
    "iss": "iss",
    "aud": "aud",
    "uid": 123,
}
try:
    create_token = CreateJwtToken(cert_dir="/tmp", payload=payload)
    if create_token.create():
        print(f"Token: {create_token.get_token()}")
except CreateTokenException as e:
    print(f"CreateTokenException: {str(e)}")
from pyjwt512 import InvalidTokenException
from pyjwt512 import VerifyJwtToken

# Valid a token
jwt_token = VerifyJwtToken()
try:
    if jwt_token.validate(token="any token", audience="any audience", cert_dir="/tmp"):
        print(f"Token is valid.")
        print(f"{jwt_token}")
except InvalidTokenException as e:
    print(f"InvalidTokenException: {str(e)}")

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

pyjwt512-0.1.18.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyjwt512-0.1.18-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file pyjwt512-0.1.18.tar.gz.

File metadata

  • Download URL: pyjwt512-0.1.18.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.0-91-generic

File hashes

Hashes for pyjwt512-0.1.18.tar.gz
Algorithm Hash digest
SHA256 d0152360351376eb776b58855bab2fdc159c9895c6fb1d608bda35b24c0426a1
MD5 af926f94210f20f77fecf03a0d9ce73c
BLAKE2b-256 490da546a4614e92ed5e200427fd4f4c08030c9a986f50f4c761fbfb67bfef23

See more details on using hashes here.

File details

Details for the file pyjwt512-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: pyjwt512-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.0-91-generic

File hashes

Hashes for pyjwt512-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 289d327a1a6ba08dc0f405872965a85f620f5a41b9b8148084bf156018e4d60c
MD5 d30e3c46ee0dab5bb976563376fa348f
BLAKE2b-256 0ac370fb9e36cdeacfa18bede386c625a362b7e95587b9956580849e61432e2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page