Skip to main content

A simple and lightweight Python package for handling JWT (JSON Web Token) operations with USSO (Unified Single Sign-On).

Project description

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, "EdDSA")

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, "EdDSA")

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.

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

usso_jwt-0.1.6.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

usso_jwt-0.1.6-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file usso_jwt-0.1.6.tar.gz.

File metadata

  • Download URL: usso_jwt-0.1.6.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for usso_jwt-0.1.6.tar.gz
Algorithm Hash digest
SHA256 602e5d2fdea86b85f10d68f8b95addbcc35f2174312d5f0887ac6bb463d9ee30
MD5 46688ba9961048739f0778f608a83f29
BLAKE2b-256 93ba9bf787e63437d2896a9a75e31df80526837ad4cdc26cfc594748b7babb45

See more details on using hashes here.

File details

Details for the file usso_jwt-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: usso_jwt-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for usso_jwt-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cfdee7e179ae2e9f4b366f708a389c39f76e511ac6e53706146afa7c43ae27b3
MD5 d2e5b5635269006a492449cbbc0b9e60
BLAKE2b-256 3c9aef2fa0531b0343da3ac83aa702c13d8cff78f1d95a5308b2c208f0e95643

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