Code Monkey home page Code Monkey logo

pyjwt512's Introduction

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)}")

pyjwt512's People

Watchers

heximcz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.