Django REST Framework authentication using PASETO (pyseto)
Project description
drf-pyseto
A simple, secure, and modern PASETO (Platform-Agnostic Security Tokens) authentication backend for Django REST Framework (DRF), powered by pyseto.
📖 Read the Full Documentation Here
drf-pyseto utilizes the v4.local (symmetric encryption) PASETO specification, providing a more secure alternative to JWTs by preventing cryptographic agility attacks and minimizing misconfigurations.
🌟 Features
- Secure by Default: Implements PASETO
v4.localensuring robust, symmetric encryption for your tokens. - Seamless Integration: Built specifically for Django REST Framework. Drop-in replacement for traditional token or JWT authentication.
- Configurable Lifetimes: Easily manage separate lifetimes for access and refresh tokens.
- Modern Python & Django Support: Compatible with Python 3.10–3.14 and Django 4.2–6.0.
📦 Requirements
- Python >= 3.10
- Django >= 4.2
- Django REST Framework >= 3.16
- pyseto >= 1.7
🚀 Installation
Install the package via pip:
pip install drf-pyseto
⚙️ Configuration
1. Update Django Settings
Add the necessary configuration for drf-pyseto in your settings.py:
DRF_PYSETO = {
# REQUIRED: A 32-byte secret key (can be plain 32-bytes or base64url encoded)
"KEY": "<your-32-byte-secret-key-or-base64url>",
# Optional settings (defaults shown)
"ACCESS_LIFETIME": 300, # Access token lifetime in seconds (default: 5 minutes)
"REFRESH_LIFETIME": 86400, # Refresh token lifetime in seconds (default: 1 day)
"USER_ID_FIELD": "id", # User model field used as the subject
"USER_ID_CLAIM": "user_id", # Claim key for the user identifier
"TOKEN_TYPE_CLAIM": "typ", # Claim key for the token type
"AUTH_HEADER_TYPE": "Bearer", # Allowed Authorization header type
# Additional standard PASETO claims (optional)
# "ISSUER": "your-service",
# "AUDIENCE": "your-clients",
}
2. Configure DRF Authentication
Set drf_pyseto as your authentication class in settings.py:
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"drf_pyseto.authentication.PASETOAuthentication",
)
}
3. Setup Routing
Include the token endpoints in your project's urls.py:
from django.urls import path, include
urlpatterns = [
# ...
path("api/auth/", include("drf_pyseto.urls")),
# ...
]
📡 Endpoints
Once configured, the following endpoints will be available to manage your tokens (assuming you included the URLs under api/auth/):
-
Obtain Tokens:
POST /api/auth/token/- Payload:
{"username": "your_username", "password": "your_password"} - Returns format:
{"access": "v4.local....", "refresh": "v4.local...."}
- Payload:
-
Refresh Access Token:
POST /api/auth/token/refresh/- Payload:
{"refresh": "v4.local...."} - Returns format:
{"access": "v4.local...."}
- Payload:
🛠️ Development & Testing
To set up the project for development and run the test suite:
# Clone the repository
git clone https://github.com/p-r-a-v-i-n/drf-pyseto.git
cd drf-pyseto
# Install locally with testing dependencies
pip install -e ".[test]"
# Run tests
pytest
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_pyseto-0.1.2.tar.gz.
File metadata
- Download URL: drf_pyseto-0.1.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a142f9a752a30f0f218f5ff8ffd47814bc9bf33dd4751e0855d4f9328c30829
|
|
| MD5 |
afed29918304866233d5b89fc23e230d
|
|
| BLAKE2b-256 |
e80395e8021e7039ab7022e7f01f5b0af62da1bc9484146cd2c8a33a298fe8d7
|
Provenance
The following attestation bundles were made for drf_pyseto-0.1.2.tar.gz:
Publisher:
release.yml on p-r-a-v-i-n/drf-pyseto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_pyseto-0.1.2.tar.gz -
Subject digest:
8a142f9a752a30f0f218f5ff8ffd47814bc9bf33dd4751e0855d4f9328c30829 - Sigstore transparency entry: 1317317945
- Sigstore integration time:
-
Permalink:
p-r-a-v-i-n/drf-pyseto@7723173967d84ca05281f8cbf36baa09b79209cf -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/p-r-a-v-i-n
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7723173967d84ca05281f8cbf36baa09b79209cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file drf_pyseto-0.1.2-py3-none-any.whl.
File metadata
- Download URL: drf_pyseto-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ebb4a94ea18cab429586ae65c9be77aeea1d7363433259af3e7f1278ac485d4
|
|
| MD5 |
fbd16b3a76266b99dea1dac5783c0df6
|
|
| BLAKE2b-256 |
0c48ac1db0c4aa77db926cdd592826502737443aed1806732db42f66564f5cb6
|
Provenance
The following attestation bundles were made for drf_pyseto-0.1.2-py3-none-any.whl:
Publisher:
release.yml on p-r-a-v-i-n/drf-pyseto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_pyseto-0.1.2-py3-none-any.whl -
Subject digest:
5ebb4a94ea18cab429586ae65c9be77aeea1d7363433259af3e7f1278ac485d4 - Sigstore transparency entry: 1317318001
- Sigstore integration time:
-
Permalink:
p-r-a-v-i-n/drf-pyseto@7723173967d84ca05281f8cbf36baa09b79209cf -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/p-r-a-v-i-n
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7723173967d84ca05281f8cbf36baa09b79209cf -
Trigger Event:
push
-
Statement type: