Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rexzhang/django-light-auth
Django Lightweight Authentication without models and databases, only depend on the Django's SessionMiddleware.
https://github.com/rexzhang/django-light-auth
auth django
Last synced: about 2 months ago
JSON representation
Django Lightweight Authentication without models and databases, only depend on the Django's SessionMiddleware.
- Host: GitHub
- URL: https://github.com/rexzhang/django-light-auth
- Owner: rexzhang
- License: mit
- Created: 2021-01-13T14:04:57.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-10T03:36:17.000Z (over 2 years ago)
- Last Synced: 2024-10-13T02:21:04.257Z (3 months ago)
- Topics: auth, django
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-light-auth
[![](https://img.shields.io/pypi/v/django-light-auth.svg)](https://pypi.org/project/django-light-auth/)
[![](https://img.shields.io/pypi/pyversions/django-light-auth.svg)](https://pypi.org/project/django-light-auth/)
[![](https://img.shields.io/pypi/dm/django-light-auth.svg)](https://pypi.org/project/django-light-auth/)> Django Lightweight Authentication without models and databases, only depend on the signed cookies and the Django's SessionMiddleware.
# Install
```shell
pip3 install -U django-light-auth
```# Usage
## Basic Usage
### `settings.py`
```python
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'
```### `urls.py`
```python
from django.urls import pathfrom django_light_auth import LoginView, LogoutView
urlpatterns = [
# ...
path('login', LoginView.as_view(), name='login'),
path('logout', LogoutView.as_view(), name='logout'),
]
```### `your_app/auth/validate_func.py`
```python
#
# 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 Truereturn False
```## Custom Login View
`your_login_view.py`
```python
from django_light_auth import LoginView as LoginViewAbsclass LoginView(LoginViewAbs):
template_name = 'your_app/login.html'
```# History
## v0.2.2 - 20220809
- Compatible Django 4.1+