Skip to main content

Python Library for XSHL Session

Project description

py-xshl-session

Session in JWT

PyPI version Python Version License: GPL v3

Python library for managing JWT/JWE sessions with key management and XSHL Target integration.

  • 🇷🇺 Russian version: see README_RU.md
  • 📚 Full docs: docs/index.mdQuickstart, Guides, API, Security
  • 🌐 Localized docs (RU): docs/ru/index.md

Features

  • 🔐 JWT/JWE support for signing and encryption
  • 🎯 XSHL integration: Target-aware JWKS loading
  • ⚡ Background refresh of JWKS with TTL
  • 🛡️ Extended claims validation via custom SessionClaims
  • 📦 JWE serialization/deserialization helpers
  • 🔍 Built-in request tracing

Constants

  • DEFAULT_SESSION_VERSION = 1
  • DEFAULT_SESSION_EXPIRES = 120
  • DEFAULT_UID = "00000000-0000-0000-0000-000000000000"
  • DEFAULT_STR = "undef"

Quickstart

See docs/quickstart.md for a complete guide.

from xshl.session.keys import Keys
from xshl.session import Session, ConfigSession
import uuid

keys = Keys(name="session_name", url="https://example.org/jwks.json")
config = ConfigSession(
    keys=keys,
    app=uuid.uuid4(),
    audience=["service-api"],
    header={"alg": "RS256", "kid": "<kid>"},
    version=1,
    expires=3600,
    key=b"<private-key-pem>"
)
session = Session(config, "trace-1", "trace-2")

session.sub = "user-123"
session.aud = "service-api"
session.scope = ["read", "write"]

jwt_token = session.jwt

Note: Session.jwt uses a JsonDumps context internally to serialize claims because Authlib JWT encoding does not expose a default hook for JSON; see API docs.

JWE helpers:

protected = {"alg": "RSA-OAEP-256", "enc": "A256GCM", "kid": "<kid>"}
serialized = session.serialize(b"payload", protected)
plaintext = session.deserialize(serialized)

Documentation

  • API details in docs/api.md
  • Configuration and operational tips in docs/guides.md
  • Security recommendations in docs/security.md

License

GPL v3 — see LICENSE and COPYRIGHT.

Contributing

  • Issues and feature requests: open on GitHub
  • Pull requests welcome. Please ensure:
    1. Tests pass
    2. Lint/style are respected
    3. Tests are added for new functionality
    4. You understand GPL v3 requirements for contributions

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

xshl_session-0.0.1.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

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

xshl_session-0.0.1-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file xshl_session-0.0.1.tar.gz.

File metadata

  • Download URL: xshl_session-0.0.1.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for xshl_session-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cf0f582c8ea0779cf01d7ad52d4b88229734feb8f08a0276313d6bd0d9ae40a5
MD5 953a7c63f69846a7f35889b730aa2da3
BLAKE2b-256 c40a8c8b1211197275e23da201d2f31861dc34abea57bdf35022fceb30b03f3e

See more details on using hashes here.

File details

Details for the file xshl_session-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: xshl_session-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for xshl_session-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f32523161f5c0039a5de981f1b8a6a8fd788c921d813730eafe696c688c9d19
MD5 c48cd55c61b207bcb00616734058cdf7
BLAKE2b-256 c80e7b1d607c9add383eb511116303e85c94eecdd97b7afa5de8c7aec8cac75c

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