Skip to content
Nat Lee

Keyboard shortcuts

Turn these off if they get in the way of a screen reader or voice control. The setting is saved in this browser.

1
Home
2
Work
3
Projects
4
About
5
Experience
/
Search projects
?
Show this panel

Web Development

Django Allauth JWT Template

Django Authentication Template

Email, Google, Microsoft and LINE login for SPAs and APIs, using django-allauth’s headless mode and built-in JWTs.

Role
Creator & Maintainer
Period
2021 – 2026.11
Status
Completed
Categories
Infrastructure & backend
Stack
  • Python
  • Django
  • django-allauth
  • JWT
  • Docker
Django Allauth JWT Template, screenshot 1

Overview

A Django authentication template built on django-allauth headless mode and its built-in JWT support. It demonstrates email and social login for separate frontends, with end-to-end verification rather than a custom session-to-JWT bridge.

What it's good for

For a project with its own frontend that wants real accounts from day one: sign-up, email confirmation, password reset, account linking and three social logins, with 65 tests behind them. The Dummy provider lets you log in as anyone locally; Django refuses to start with it once debug is off.

Diagrams

Main paths only. The edge cases stayed in the code.

After logging out, a 401 is the good news.

Point at a box to see what it connects to.

  1. Sign up or log in(email or three social logins) → Password or a provider?
  2. Password or a provider? → password: Post email and password → social login: Redirect to the provider
  3. Post email and password(app endpoint, no cookies) → Get a JWT pair
  4. Redirect to the provider(browser endpoint, session cookie) → Email already has an account?
  5. Email already has an account? → taken, log in: Sign up or log in → no: Swap the session for JWTs
  6. Swap the session for JWTs(POST /api/auth/jwt) → Get a JWT pair
  7. Get a JWT pair(5-minute access, 1-day refresh) → Call your API with Bearer
  8. Call your API with Bearer → Access token expired?
  9. Access token expired? → not yet: Call your API with Bearer → yes: Refresh for a new pair
  10. Refresh for a new pair(old refresh token works once) → Still using the API?
  11. Still using the API? → yes: Call your API with Bearer → no: Log out, both tokens die
  12. Log out, both tokens die(a 401 here means success)

Features

  • Headless authentication with built-in JWT support
  • Email, Google, Microsoft and LINE login
  • Separate SPA/API frontend integration
  • End-to-end authentication checks

Results

  • Authentication template built on django-allauth’s supported headless interfaces
The demo page: the decoded access token, both JWTs and a 200 from /api/me. 4:54 left.
The demo page: the decoded access token, both JWTs and a 200 from /api/me. 4:54 left.

What I learned

  • The old template's Simple JWT access token lived 60 hours; allauth's lives five minutes, and each refresh token works exactly once.
  • Logout ends access tokens at once only with JWT_STATEFUL_VALIDATION on; turn it off and they live until expiry, saving a session lookup per request.
  • A provider login whose email already has an account is refused, so owning a Google account with the same address isn't enough to get in.
  • Infrastructure & backend1313 stars on GitHub

    Telepy

    One outbound reverse SSH tunnel per device gives you a browser terminal, files, remote desktop, a remote browser and the LAN behind it. No port forwarding, no VPN, no public IP.

    2024Active
  • Infrastructure & backend66 stars on GitHub

    Dev Dock Manager (Rust)

    One Docker dev box per user, with a web terminal, a noVNC desktop and optional GPU. The Django version, rewritten in Rust, partly to find out whether I could.

    2023Active
  • Spin-off · Contract work
    Infrastructure & backend11 stars on GitHub

    Blockchain from Scratch

    Nine hands-on chapters, from hashing to a peer-to-peer network. The same Rust code powers interactive WebAssembly demonstrations in your browser.

    2018Completed