{"id":21141,"library":"django-authlib","title":"django-authlib","description":"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.","status":"active","version":"0.17.2","language":"python","source_language":"en","source_url":"https://github.com/matthiask/django-authlib/","tags":["django","authentication","oauth2","saml","openid-connect"],"install":[{"cmd":"pip install django-authlib","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core dependency for Django framework","package":"django","optional":false},{"reason":"Used for OAuth2 and other HTTP requests","package":"requests","optional":true}],"imports":[{"note":"Views are under authlib.views","wrong":"from authlib import LoginView","symbol":"LoginView","correct":"from authlib.views import LoginView"},{"note":"OAuth2 client moved to authlib.oauth2 in 0.17","wrong":"from authlib.client import OAuth2Client","symbol":"OAuth2Client","correct":"from authlib.oauth2 import OAuth2Client"}],"quickstart":{"code":"import os\nfrom django.conf import settings\nfrom django.urls import path\nfrom authlib.views import LoginView, LogoutView\n\n# Ensure required settings\nif not settings.configured:\n    settings.configure(\n        DEBUG=True,\n        SECRET_KEY='test-secret',\n        ROOT_URLCONF=__name__,\n        AUTH_USER_MODEL='auth.User',\n        AUTH_TOKEN_URL=os.environ.get('AUTH_TOKEN_URL', 'https://provider/token'),\n        AUTH_CLIENT_ID=os.environ.get('AUTH_CLIENT_ID', 'client-id'),\n        AUTH_CLIENT_SECRET=os.environ.get('AUTH_CLIENT_SECRET', 'secret'),\n    )\n\nurlpatterns = [\n    path('login/', LoginView.as_view(), name='login'),\n    path('logout/', LogoutView.as_view(), name='logout'),\n]\n\nif __name__ == '__main__':\n    from django.core.management import execute_from_command_line\n    execute_from_command_line(['manage.py', 'runserver'])\n","lang":"python","description":"Minimal setup with login/logout views using environment variables for OAuth2 credentials."},"warnings":[{"fix":"Update imports to use authlib.oauth2.OAuth2Client instead of authlib.client.OAuth2Client.","message":"In version 0.17, the OAuth2 client was moved from authlib.client to authlib.oauth2. Old imports will break.","severity":"breaking","affected_versions":">=0.17"},{"fix":"Use django-saml2 or python3-saml instead.","message":"The SAML support in authlib.saml is deprecated in favor of third-party libraries.","severity":"deprecated","affected_versions":">=0.16"},{"fix":"Ensure these settings are defined in Django settings.py or via environment variables.","message":"Setting AUTH_TOKEN_URL, AUTH_CLIENT_ID, and AUTH_CLIENT_SECRET in Django settings is mandatory; missing these will cause runtime errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Create a custom user model or use Django's default auth.User; ensure proper fields are present.","message":"The package does not include migrations; user model must already exist with appropriate fields (e.g., email, username).","severity":"gotcha","affected_versions":"all"},{"fix":"Update URL references in templates or redirects to use the new path.","message":"As of 0.16, the callback URL pattern changed from /auth/callback/ to /auth/complete/. Custom templates may break.","severity":"breaking","affected_versions":">=0.16,<0.17"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"from authlib.oauth2 import OAuth2Client","cause":"The module authlib.client was removed in 0.17. OAuth2Client is now in authlib.oauth2.","error":"ImportError: cannot import name 'OAuth2Client' from 'authlib.client'"},{"fix":"Add AUTH_TOKEN_URL, AUTH_CLIENT_ID, and AUTH_CLIENT_SECRET to your Django settings or environment variables.","cause":"Missing required settings in Django configuration.","error":"django.core.exceptions.ImproperlyConfigured: The AUTH_TOKEN_URL setting is required."},{"fix":"Uninstall any other authlib package and install django-authlib: pip uninstall authlib; pip install django-authlib","cause":"The package is not installed correctly or a different library named authlib is installed.","error":"AttributeError: module 'authlib' has no attribute 'views'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}