Skip to main content

django-auth-events

PyPI version Python License: MIT Tests

Auth session event consumer for Django. Bridges event-driven session invalidation with JWT token validation.

Combines streambus (event consumption) with django-auth-external (token validation) to reject tokens whose sessions have been explicitly invalidated — without tight coupling between services.

how it works

One service publishes a SessionInvalidatedEvent to an event stream whenever a user's access changes. Each Django service runs consume_auth_events, which receives those events and stores the invalidation state in Django's cache. The AuthEventsMiddleware checks that state on every request.

Token validation and invalidation are both in the middleware — no Redis dependency in the library itself. The cache backend is whatever you configure in Django's CACHES setting.

install

pip install django-auth-events

setup

Add the middleware (replaces AuthExternalMiddleware from django-auth-external):

MIDDLEWARE = [
    ...
    "django_auth_events.middleware.AuthEventsMiddleware",
]

Configure auth and event settings:

AUTH_EXTERNAL = {
    "SECRET_KEY": "your-secret-key",
    "CLAIMS": ["user_id", "email"],
}

AUTH_EVENTS = {
    "STREAM": "auth:session:events",
    "GROUP": "my-service",
    "REDIS_URL": "redis://localhost:6379",
    "CACHE_TTL": 86400,
}

Configure the cache backend (Redis recommended for multi-process deployments):

CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": "redis://localhost:6379",
    }
}

Run the consumer:

python manage.py consume_auth_events

events

Publish a SessionInvalidatedEvent from any service to invalidate a user's active tokens:

from django_auth_events import SessionInvalidatedEvent
from streambus import EventPublisher
from streambus.transports.redis_streams import RedisStreamsTransport
from streambus.config import RedisConfig

transport = RedisStreamsTransport(RedisConfig(url="redis://localhost:6379"))
publisher = EventPublisher(stream="auth:session:events", transport=transport)
publisher.publish(SessionInvalidatedEvent(event_type="session.invalidated", user_id="abc-123"))

configuration

Key Default Description
STREAM "auth:session:events" Redis Stream key to consume from.
GROUP "django-auth-events" Consumer group name. Use a unique name per service.
REDIS_URL "redis://localhost:6379" Redis URL for the event stream.
CACHE_TTL 86400 Invalidation record TTL in seconds (24 hours).

license

MIT

Metadata

Release files for django-auth-events 0.1.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 django-auth-events 0.1.1
File Size Uploaded Provenance Actions
django_auth_events-0.1.1.tar.gz 12.2 kB With provenance Details for django_auth_events-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-auth-events 0.1.1
File Interpreter ABI Platform Actions
django_auth_events-0.1.1-py3-none-any.whl Python 3 none any Details for django_auth_events-0.1.1-py3-none-any.whl

Total release size: 20.1 kB

Release files / django_auth_events-0.1.1.tar.gz

Download URL django_auth_events-0.1.1.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2785daa3a5958f5d54476626d856cf342192aef989252ce4f5d0bf124b60d24b
BLAKE2b-256 checksum
How to use checksums
f5f7e175f417c0f2deeafefdf5f9cfacdc8678089ec9838b7c080af498533e47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / django_auth_events-0.1.1-py3-none-any.whl

Download URL django_auth_events-0.1.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6d882e5e77a54ab3709e4224d889eb6cd8f88a242a6c449417b6b083d66de80
BLAKE2b-256 checksum
How to use checksums
55329b2773155f1c9b2ce7e336a6f574b94751ae18bfcaa4f88f2d962327f227
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Security for django-auth-events 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_auth_events-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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