Django Ninja API Key Authentication
Project description
Ninja API Key
API Key authentication for Django Ninja.
This is a fork from django-ninja-apikey.
Key Features:
- Easy integration into your projects
- Well integrated with the Admin interface
- Secure API keys due to hashing
- Works with the standard user model
Installation
pip install ninja-api-key
How to use
- Add
ninja_apikeyto your installed apps in your Django project:
# settings.py
INSTALLED_APPS = [
# ...
"ninja_apikey",
]
- Apply migrations
python manage.py migrate
-
Secure
a. the whole API
# api.py from ninja import NinjaAPI from ninja_apikey.security import APIKeyAuth # ... api = NinjaAPI(auth=APIKeyAuth()) # ... @api.get("/secure_endpoint") def secure_endpoint(request): return f"Hello, {request.user}!"
b. an specific endpoint
# api.py from ninja import NinjaAPI from ninja_apikey.security import APIKeyAuth # ... auth = APIKeyAuth() api = NinjaAPI() # ... @api.get("/secure_endpoint", auth=auth) def secure_endpoint(request): return f"Hello, {request.user}!"
-
ninja-api-key uses
settings.PASSWORD_HASHERSto hash the API keys. Django's defaultPBKDF2PasswordHashermay be slow depending on the number of iterations. You can change thesettings.PASSWORD_HASHERSto use a faster (but less secure) one. ninja-api-key provides aSHA256PasswordHasher.# settings.py PASSWORD_HASHERS = [ "ninja_apikey.hashers.SHA256PasswordHasher", # others ]
⚠️ Keep in mind that this will affect Django authentication as a whole, not just ninja-api-key.
Changelog
See CHANGELOG.md for a detailed history of changes and releases.
Contributing
Contributions are welcome; feel free to open an Issue or Pull Request.
git clone https://github.com/lucasrcezimbra/ninja-api-key
cd ninja-api-key
python -m venv .venv
source .venv/bin/activate
pip install .[test]
pre-commit install
make test
Project details
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 ninja_api_key-2.0.0.tar.gz.
File metadata
- Download URL: ninja_api_key-2.0.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dbc2390d13671ff336377068e83504fa1819a2fe6acbc58ce8afe00a290527c
|
|
| MD5 |
a46870e48d6e2d7439efd8bf759e1704
|
|
| BLAKE2b-256 |
b5752b453e2055beef8bd1e3b9a66513b4487325736db4f5d85b03e474cdc9a0
|
Provenance
The following attestation bundles were made for ninja_api_key-2.0.0.tar.gz:
Publisher:
publish.yml on lucasrcezimbra/ninja-api-key
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ninja_api_key-2.0.0.tar.gz -
Subject digest:
3dbc2390d13671ff336377068e83504fa1819a2fe6acbc58ce8afe00a290527c - Sigstore transparency entry: 798358017
- Sigstore integration time:
-
Permalink:
lucasrcezimbra/ninja-api-key@982bd07ef0241715e02e17eeef7c18140b083162 -
Branch / Tag:
refs/tags/2.0.0 - Owner: https://github.com/lucasrcezimbra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@982bd07ef0241715e02e17eeef7c18140b083162 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ninja_api_key-2.0.0-py3-none-any.whl.
File metadata
- Download URL: ninja_api_key-2.0.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6da7d4900953747d2b8f7cca7de1d005eb3996cd2d9a2032d5eaaddd5eed267b
|
|
| MD5 |
cf903cc3b0321bc68a6fa60956f7f12e
|
|
| BLAKE2b-256 |
65268a9982dc656e2c905bda8438299ccfd75c7f1957c78758f7f602f0a7e23a
|
Provenance
The following attestation bundles were made for ninja_api_key-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on lucasrcezimbra/ninja-api-key
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ninja_api_key-2.0.0-py3-none-any.whl -
Subject digest:
6da7d4900953747d2b8f7cca7de1d005eb3996cd2d9a2032d5eaaddd5eed267b - Sigstore transparency entry: 798358020
- Sigstore integration time:
-
Permalink:
lucasrcezimbra/ninja-api-key@982bd07ef0241715e02e17eeef7c18140b083162 -
Branch / Tag:
refs/tags/2.0.0 - Owner: https://github.com/lucasrcezimbra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@982bd07ef0241715e02e17eeef7c18140b083162 -
Trigger Event:
release
-
Statement type: