Skip to main content

USSO-JWT

A secure and flexible JWT (JSON Web Token) implementation for Python, designed to work seamlessly with the USSO authentication system. This library provides a robust set of tools for creating, signing, verifying, and managing JWTs with support for multiple cryptographic algorithms.

Features

  • Multiple Algorithm Support:

    • HMAC (HS256, HS384, HS512)
    • RSA (RS256, RS384, RS512, PS256, PS384, PS512)
    • ECDSA (ES256, ES384, ES512)
    • EdDSA (Ed25519)
  • JWK Support: Full support for JSON Web Keys (JWK) format

  • PEM Support: Load keys from PEM-encoded files

  • Type Safety: Built with type hints for better IDE support and code safety

  • Comprehensive Testing: Thorough test coverage for all algorithms and features

Installation

Install using pip:

pip install usso-jwt

Quick Start

Creating and Signing a JWT

from usso_jwt import JWT

# Create a JWT with a payload
jwt = JWT(payload={"sub": "1234567890", "name": "John Doe", "iat": 1516239022})

# Sign with HMAC
token = jwt.sign(hmac_key, "HS256")

# Sign with RSA
token = jwt.sign(rsa_private_key, "RS256")

# Sign with ECDSA
token = jwt.sign(ecdsa_private_key, "ES256")

# Sign with EdDSA
token = jwt.sign(eddsa_private_key, "Ed25519")

Verifying a JWT

from usso_jwt import JWT

# Verify with HMAC
jwt = JWT.verify(token, hmac_key, "HS256")

# Verify with RSA
jwt = JWT.verify(token, rsa_public_key, "RS256")

# Verify with ECDSA
jwt = JWT.verify(token, ecdsa_public_key, "ES256")

# Verify with EdDSA
jwt = JWT.verify(token, eddsa_public_key, "Ed25519")

Working with JWKs

from usso_jwt import JWT

# Create a JWT with a JWK
jwt = JWT(payload={"sub": "1234567890"})

# Sign with a JWK
token = jwt.sign(jwk, "RS256")

# Verify with a JWK
jwt = JWT.verify(token, jwk, "RS256")

Supported Algorithms

HMAC (Symmetric)

  • HS256: HMAC with SHA-256
  • HS384: HMAC with SHA-384
  • HS512: HMAC with SHA-512

RSA (Asymmetric)

  • RS256: RSA with SHA-256
  • RS384: RSA with SHA-384
  • RS512: RSA with SHA-512
  • PS256: RSA-PSS with SHA-256
  • PS384: RSA-PSS with SHA-384
  • PS512: RSA-PSS with SHA-512

ECDSA (Asymmetric)

  • ES256: ECDSA with P-256 and SHA-256
  • ES384: ECDSA with P-384 and SHA-384
  • ES512: ECDSA with P-521 and SHA-512

EdDSA (Asymmetric)

  • EdDSA: Ed25519

Security Considerations

  • Always use strong keys appropriate for your chosen algorithm
  • For HMAC, use keys at least as long as the hash output (e.g., 32 bytes for HS256)
  • For RSA, use keys of at least 2048 bits
  • For ECDSA, use the recommended curves (P-256, P-384, P-521)
  • Store private keys securely and never expose them
  • Use appropriate key rotation policies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for usso-jwt 0.2.18

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

Source distribution (sdist)

Source distribution for usso-jwt 0.2.18
File Size Uploaded
usso_jwt-0.2.18.tar.gz 28.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for usso-jwt 0.2.18
File Interpreter ABI Platform
usso_jwt-0.2.18-py3-none-any.whl Python 3 none any Details

Total release size: 55.8 kB

Release files / usso_jwt-0.2.18.tar.gz

Download URL usso_jwt-0.2.18.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a5333d12996d27c6cc0f11d76ed344ebc4b0c2f1bda1e84dd4afd64fd697bc46
BLAKE2b-256 checksum
How to use checksums
32bbfeca3a0530e2c94feda35b0f20f82f01a7eecd2e3715cd5acd290d9a574e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / usso_jwt-0.2.18-py3-none-any.whl

Download URL usso_jwt-0.2.18-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e31735654ff5587e0af7396e075a4e882a25dfd336de88199999bd3c93303f3c
BLAKE2b-256 checksum
How to use checksums
371c07d1927047e91016844ec79c2f324e7653ebc8a4e27c32e1a638c2efda1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.2.18 This release

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.6

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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