Django Lightweight Authentication without models and databases, only depend on the signed cookies and the Django's SessionMiddleware.
pip3 install -U django-light-auth
INSTALLED_APPS = [
# ...
# 'django.contrib.auth',
'django_light_auth.apps.DjangoLightAuthConfig',
# ...
]
MIDDLEWARE = [
# ...
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_light_auth.LightAuthMiddleware'
# ...
]
# Session
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
# django-light-auth
LIGHT_AUTH_VALIDATE_FUNC = 'your_app.auth.validate_func'
from django.urls import path
from django_light_auth import LoginView, LogoutView
urlpatterns = [
# ...
path('login', LoginView.as_view(), name='login'),
path('logout', LogoutView.as_view(), name='logout'),
]
#
# example at django_light_auth.light_auth_validate_func
#
from typing import Dict, Any
from your_app.config import config
def light_auth_validate_func(data: Dict[str, Any]) -> bool:
if data.get('username', None) == config.Auth.username and data.get(
'password', None
) == config.Auth.password:
return True
return False
your_login_view.py
from django_light_auth import LoginView as LoginViewAbs
class LoginView(LoginViewAbs):
template_name = 'your_app/login.html'
- Compatible Django 4.1+