Skip to main content

Python JWT Signature Validator - Asymetric Keys - From exponent and modulus

Project description

py-jwt-validator

JWT Signature Validator, for JWT signed with Asymmetric Keys, public key compiled from exponent and modulus.


Disclaimer

Currently, this package is just in beta status. More work is required until it can be considered "production ready".


Version:

0.0.1-beta


Install

pip install py-jwt-validator

Usage Guide

from py_jwt_validator import PyJwtValidator, PyJwtException
jwt = {access_token / id_token}
try:
    _jwt = PyJwtValidator(jwt)
except PyJwtException:
    print('Exception was catched.')

The class PyJwtValidator currently accepts:

  • jwt - only mandatory argument
  • cid - OIDC Client ID - optional
  • aud - Audience - optional
  • iss - Issuer - optional

Process Chain

  • Once the class is instantiated the following checks are performed:

    • JWT Format
    • JWT Expiration time
    • JWT Claims if given when the class was instantiated.
  • After the above checks are done, it will verify the token signature with the public exponent and modulus obtained from the /keys endpoint. If the signature is valid, it will return None. Else, it will raise exception.

    • If a check fails at any given step, the exception PyJwtException will be raised.
    • The /keys endpoint will be compiled based on the 'iss' claim.
    • The response from /keys will be cached (requests_cache) for subsequent calls. Cache lifetime hardcoded to 24 hours. Cache store is sqlite.
  • return_data() method can be used after all checks are passed.


Note

The reason why this class returns None or exception is to provide more flexibility. Not everyone needs to return the decoded payload of the jwt.

It is recommended to use it within try: except blocks.


UPCOMING IN FUTURE RELEASES

  • Custom Claim validation
  • Cache Control (use-case, cache-expiry)
  • Return Payload or None

SUGGESTIONS?

Please feel free to email me at adrian.lazar95@outlook.com or adrian.lazar@okta.com. I am opened to improvement / suggestions and critics.

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

py_jwt_validator-0.0.1b0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

py_jwt_validator-0.0.1b0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file py_jwt_validator-0.0.1b0.tar.gz.

File metadata

  • Download URL: py_jwt_validator-0.0.1b0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

File hashes

Hashes for py_jwt_validator-0.0.1b0.tar.gz
Algorithm Hash digest
SHA256 ec82264025d0bb3bc52c2cf3b6a39dd6ac634bd1172cd655294d0baadfdde0e1
MD5 6aea5a5e8af5fd0f64af4db249843728
BLAKE2b-256 e8be72e8fb50b1778bf25d126dd4c7a193bbc49b654dc3bf4bf8bd0c3be70df8

See more details on using hashes here.

File details

Details for the file py_jwt_validator-0.0.1b0-py3-none-any.whl.

File metadata

  • Download URL: py_jwt_validator-0.0.1b0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

File hashes

Hashes for py_jwt_validator-0.0.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e83fc46d18993395f7638e646e48cee555356f4145882f00fde452673cfdb8b
MD5 14fc7e23002d2f720cfae98588adb497
BLAKE2b-256 fc230bd2fb5ab066bae777394fefa7482e3f5f1191cd17943557cda1caf28a48

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