django-auth-events
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_auth_events-0.1.0.tar.gz | 12.1 kB | With provenance | Details for django_auth_events-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_auth_events-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_auth_events-0.1.0-py3-none-any.whl |
Total release size: 19.9 kB
Release files / django_auth_events-0.1.0.tar.gz
| Download URL | django_auth_events-0.1.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6ea3382c4e120351488dd9d9648c92432ddb94ede3de07d218df1d0206fb1d3
|
|
BLAKE2b-256 checksum How to use checksums |
47e23687e8f6748937b38e78c9847d55e9438e5de44514e18674adda131e8db9
|
| 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 24, 2026.
Transparency logRelease files / django_auth_events-0.1.0-py3-none-any.whl
| Download URL | django_auth_events-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b330c10a19754b2eaf9f921867bb556cefa1f2950a3b17812a1312f968d39d08
|
|
BLAKE2b-256 checksum How to use checksums |
35212c6b0b9d9fe0c8406b2d78d7981b541e07d5cca0673e532f25d2ba834f61
|
| 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 24, 2026.
Transparency logSecurity for django-auth-events 0.1.0
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.
Attestation for django_auth_events-0.1.0.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 24, 2026.
Transparency logA 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.