Registry / web-framework / django-authlib

django-authlib

JSON →
library0.17.2pypypiunverified

Authentication utilities for Django, providing reusable views and helpers for OAuth2, SAML, OpenID Connect, and more. Current version 0.17.2, requires Python >=3.9. Released irregularly, maintained by matthiask.

pip install django-authlib
INSTALL
IMPORT
SIG · DJANGO-AUTHLIB
D
django-authlib
web-frameworkpythonv0.17.2
Install
2.3s avg
Import
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.17.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 22.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.000s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LoginView
from authlib.views import LoginView
from authlib.views import LoginView

Minimal setup with login/logout views using environment variables for OAuth2 credentials.

import os from django.conf import settings from django.urls import path from authlib.views import LoginView, LogoutView # Ensure required settings if not settings.configured: settings.configure( DEBUG=True, SECRET_KEY='test-secret', ROOT_URLCONF=__name__, AUTH_USER_MODEL='auth.User', AUTH_TOKEN_URL=os.environ.get('AUTH_TOKEN_URL', 'https://provider/token'), AUTH_CLIENT_ID=os.environ.get('AUTH_CLIENT_ID', 'client-id'), AUTH_CLIENT_SECRET=os.environ.get('AUTH_CLIENT_SECRET', 'secret'), ) urlpatterns = [ path('login/', LoginView.as_view(), name='login'), path('logout/', LogoutView.as_view(), name='logout'), ] if __name__ == '__main__': from django.core.management import execute_from_command_line execute_from_command_line(['manage.py', 'runserver'])
Debug
Known issues
breakingIn version 0.17, the OAuth2 client was moved from authlib.client to authlib.oauth2. Old imports will break.
fix
Update imports to use authlib.oauth2.OAuth2Client instead of authlib.client.OAuth2Client.
affects: >=0.17
deprecatedThe SAML support in authlib.saml is deprecated in favor of third-party libraries.
fix
Use django-saml2 or python3-saml instead.
affects: >=0.16
gotchaSetting AUTH_TOKEN_URL, AUTH_CLIENT_ID, and AUTH_CLIENT_SECRET in Django settings is mandatory; missing these will cause runtime errors.
fix
Ensure these settings are defined in Django settings.py or via environment variables.
affects: all
gotchaThe package does not include migrations; user model must already exist with appropriate fields (e.g., email, username).
fix
Create a custom user model or use Django's default auth.User; ensure proper fields are present.
affects: all
breakingAs of 0.16, the callback URL pattern changed from /auth/callback/ to /auth/complete/. Custom templates may break.
fix
Update URL references in templates or redirects to use the new path.
affects: >=0.16,<0.17
Upgrade
Version history
0.17.2latest on PyPI · released Nov 18, 2024
Audit
Dependencies
djangorequiredCore dependency for Django framework
requestsoptionalUsed for OAuth2 and other HTTP requests
Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
django-authlib — pip install django-authlib · libregistry