Solution skill
Django login with Authlib: authorize, callback, and session
Complete solution
Django has no official Auth0 SDK; Authlib is the documented path. The traps are the callback URL built with reverse, storing the token in the session, and clearing it on logout. Not the full reference manual.
TL;DR: Django has no official Auth0 SDK; Authlib is the documented path. The traps are the callback URL built with reverse, storing the token in the session, and clearing it on logout. Login and callback views 5. Allowed Callback URLs must include the absolute callback URL you build with reverse("callback") (scheme + host + path, exact).
Django login with Authlib
1. Install
pip install "authlib~=1.0" "django~=4.0" python-dotenv requests2. Settings
Keep these out of source control:
AUTH0_DOMAIN YOUR-TENANT-DOMAIN
AUTH0_CLIENT_ID [your value]
AUTH0_CLIENT_SECRET [your value]3. OAuth client
In views.py:
from authlib.integrations.django_client import OAuth
from django.conf import settings
oauth = OAuth()
oauth.register(
"auth0",
client_id=[your value]
client_secret [your value] value]
client_kwargs={"scope": "openid profile email"},
server_metadata_url=f"https://{settings.AUTH0_DOMAIN}/.well-known/openid-configuration",
)The metadata URL gives Authlib the authorize, token, and JWKS endpoints with no hardcoding.
4. Login and callback views
from django.shortcuts import redirect
from django.urls import reverse
def login(request):
return oauth.auth0.authorize_redirect(
request, request.build_absolute_uri(reverse("callback"))
)
async def callback(request):
token [your value] value] oauth.auth0.authorize_access_token(request)
request.session["user"] = token["userinfo"]
return redirect(request.build_absolute_uri(reverse("index")))
def logout(request):
request.session.clear()
return redirect(
f"https://{settings.AUTH0_DOMAIN}/v2/logout?"
+ urlencode({"returnTo": request.build_absolute_uri(reverse("index")),
"client_id": settings.AUTH0_CLIENT_ID})
)5. Register URLs
Application type: Regular Web Application. Allowed Callback URLs must include the absolute callback URL you build with reverse("callback") (scheme + host + path, exact). Allowed Logout URLs must include the returnTo origin.
Checklist
.well-known/openid-configurationis the single source of endpoints.- Session backend is configured (default DB sessions are fine to start).
- Logout clears the Django session AND hits /v2/logout or the Auth0 session survives.
When to use this
- This covers exactly what the title says: Django login with Authlib.
- You are setting this up for the first time, or auditing an existing setup.
- You want the key gotchas in one place before you start.
When not to use this
- You are doing a different workflow with Django; these steps are specific to the title above.
- You need the full reference docs; this is the short path, not the manual.
Compatibility
- Mentions 1.0, 4.0 in the original; behavior may differ on much older or newer releases.
Evidence
Auth0's Django quickstart documents authlib~=1.0 with the Django OAuth client, authorizeredirect with request.buildabsoluteuri(reverse('callback')), authorizeaccess_token in the callback view, storing userinfo in the session, and the v2/logout redirect. Verified against live docs 2026-09-26.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_2I7BRVtsIjtk01ZYMDxnYw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Django login with Authlib: authorize, callback, and session <span>— Vectle</span></a>