Skip to main content

django-httponly-jwt

JWT sessions for Django in HttpOnly cookies, renewed by the server so quietly that the frontend never holds a token.

PyPI Python Django CI Coverage Docs Licence

فارسی · Documentation · Design · Example

Signing in sets two HttpOnly cookies. When the access token runs out, the server renews it on the way through - the request that found it expired is answered, and the answer carries the new one. The frontend sends requests with the cookies and goes to the sign-in screen on a 401; it never reads, stores or refreshes a token, and no script on the page can.

  • Renews when the browser has already deleted the expired cookie - the case the obvious middleware breaks.
  • Never rotates in the middleware, so two tabs renewing together do not sign each other out. Rotation is the refresh view's, and it blacklists the old token.
  • Ends a session at the next renewal when the account is switched off, or the project says so - not weeks later, when the refresh token expires.
  • Each person's session: its length (staff for a day, customers for a month), and claims such as the role, read again at every renewal.
  • Refuses at start-up what cannot work or protects nothing: SameSite=None without a CSRF check, renewal not installed, no blacklist.
  • Native apps and scripts use Authorization: Bearer and get their tokens in the body; a frontend on another site gets Django's CSRF check back.
  • Signals for an audit trail, drf-spectacular descriptions, sync and async, English and Persian.

It is a layer over djangorestframework-simplejwt: simplejwt mints and checks the tokens; how a person proves who they are stays the project's.

Installing

pip install django-httponly-jwt
# settings.py
INSTALLED_APPS = [..., 'rest_framework_simplejwt.token_blacklist', 'httponly_jwt']

MIDDLEWARE = [..., 'httponly_jwt.middleware.RenewalMiddleware', ...]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'httponly_jwt.authentication.CookieAuthentication',
        'httponly_jwt.authentication.HeaderAuthentication',
    ],
}
# views.py - the project signs the person in, its own way, then:
from httponly_jwt.sessions import start_session


class SignInView(APIView):
    permission_classes = (AllowAny,)

    def post(self, request):
        person = verify_code(request.data['phone'], request.data['code'])
        return start_session(Response({'id': person.pk}), person, request=request)
# urls.py
from httponly_jwt.views import RefreshView, SignOutView

urlpatterns = [
    path('auth/sign-in/', SignInView.as_view()),
    path('auth/refresh/', RefreshView.as_view()),
    path('auth/sign-out/', SignOutView.as_view()),
]
// The frontend: the cookies go with every request, and 401 means sign in again.
const answer = await fetch('https://api.example.com/me/', { credentials: 'include' })

That is all of it: from there every request from the browser carries the cookies, the middleware renews the access token when it runs out, and request.user is the person. The documentation has the rest - lifetimes and claims, the frontend, a frontend on another site, apps, signals, the schema, every setting and every check - and example/ has all of it running.

Django 5.2 to 6.1, Python 3.11 to 3.14.

Working on it

Every check runs through nox, the same sessions locally and in CI. With uv installed, a Python that is missing is fetched for you.

uv tool install nox
nox -s lint
nox -s types
nox -s tests

tests runs every supported Python and Django, with 100% coverage; one combination is nox -s "tests(3.13-django6.1)", and nox -l lists them all. package builds the wheel and runs the suite and the example against it. messages extracts the marked strings again and fails if the Persian catalogue is missing one; it needs gettext. docs builds the documentation site and fails on any link it cannot follow; nox -s docs -- serve shows it while it is written.

Licence

BSD 3-Clause - see LICENSE.

Metadata

Release files for django-httponly-jwt 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-httponly-jwt 0.1.1
File Size Uploaded Provenance Actions
django_httponly_jwt-0.1.1.tar.gz 81.5 kB With provenance Details for django_httponly_jwt-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 110.0 kB

Release files / django_httponly_jwt-0.1.1.tar.gz

Download URL django_httponly_jwt-0.1.1.tar.gz
Size 81.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a7b420321421f2bb69f3304edf180eed078704d2b8feb3dfc0ea13ecef8e2eb0
BLAKE2b-256 checksum
How to use checksums
e45447b4c71f4933ea103f708527e039560b26fce97c14a4a5353ddb65d8d23b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 16, 2026.

Transparency log

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

Download URL django_httponly_jwt-0.1.1-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47796b2831cc37832bff67b6402668289acdb02a5f0ea01ed4d9153c986a9ee0
BLAKE2b-256 checksum
How to use checksums
23843da627f69d10c61258a0c66617259e8e4f207ab5fcc72ee7eeb8ea17df14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 16, 2026.

Transparency log

Security for django-httponly-jwt 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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_httponly_jwt-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 Nov 16, 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