Skip to main content

CodeFactor

jwkaas

Python JSON Web Key Advanced Acquiring Store

Introduction to JWT, JWS and JWK

This Python module provides JSON Web Token decoding and verification. The validity of a JWT is based on theJSON Web Signature (JWS). A signature is verified using the corresponding JSON Web Key (JWK). Many identify providers publish the JSON Web Keys to verify their signatures as a JSON document on the Internet (these are referred to as the JWKS). A JWT may contain several claims (see RFC 7519). jwkaas will check the exp and nbf claim based on the current time. The aud and iss claim will be verified based on whether this information was specified on initialization (see Usage below)

Introduction to jwkaas

The Python module jwkaas provides the functionality to verify a JWT and decode it to get the information from the JWT. It includes acquiring and storing the JWKS required to verify the signatures.

Usage

The functionality is provided by the JWKaas class. On initialization the expected audience and issuer must specified. A JWT will only be accepted if the values match the corresponding token claims aud and iss. The JWKS can be specified by an url from where the JWKS json can be downloaded, and/or by a file containing the JWKS json. If both sources contain a key with the same key id (kid), the key from the url will precede the key from the file. Example initialisation:

my_jwkaas = JWKaas('https://my.audience'", 
                   'https://my.iam.server/issueing/the/token',
                   jwks_url='https://my.iam.server/well-known/keys.jwks')

Verifying and decoding a JWT is done by the JWKaas.get_token_info, like this:

token_info = my_jwkaas.get_token_info(token)
if token_info is not None:
    logging.info("Token info: %s", token_info)
else:
    logging.info("Token is invalid")

Using jwkaas with Connexion OpenAPI First framework for Python

JWKaas also provides JWKaas.get_connexion_token_info. This returns the token_info extended with the scope key as used by Connexion. The value of scope will be copied from the scp claim, which is the claim used by Azure AD to specify the scopes. Other IAM servers might use yet another claim to specify the scopes, those are currently not implemented.

Acknowledgements

jwkaas is build around PyJWT, a Python implementation of RFC 7519.

Testing

Run ```python -m nose

Metadata

Release files for jwkaas 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jwkaas 1.0.1
File Size Uploaded
jwkaas-1.0.1.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jwkaas 1.0.1
File Interpreter ABI Platform
jwkaas-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.5 kB

Release files / jwkaas-1.0.1.tar.gz

Download URL jwkaas-1.0.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
64539313db5f45118f3b02e370a8a5883ee8aba9e950682ddd3e6b49a029075f
BLAKE2b-256 checksum
How to use checksums
3d1651ba22dc3fd17e25a6c3686a1be500f7267bdf2c769ab1ea2babf4e36af4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.3

Release files / jwkaas-1.0.1-py3-none-any.whl

Download URL jwkaas-1.0.1-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c15b8ee544bec40ca651ec2d8f17c1da8e2a256d84d272225a3bf0ad68d118ba
BLAKE2b-256 checksum
How to use checksums
d6d1bf93f3b7917d2a94fce45b12026a07acb51cafec5c35fedd0e0d723d6242
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.10

2 release files

0.9

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page