Django REST URL Token Authentication
Simple extension for Django REST Framework to allow for simple url token authentication. Adds
an authentication option for passing a token key as an url parameter: ?token=sometoken and
allows for managing tokens through the admin (similar to Tastypie).
This could be useful for example when needing to share some data through a simple API with an external group where you don't want to make a user account for the group on your application.
By default, the token only gives READ ONLY permission to requests, but this can be adjusted to allow url token authentication for all requests.
Installation
-
Add "django_rest_urltoken_auth" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [ ... 'django_rest_urltoken_auth', ] -
Run
python manage.py migrateto create the apps models.
Quick start
-
Create URL API tokens in the admin:
/admin/django_rest_urltoken_auth/urltokens/ -
Set permission of the DRF view/viewset to IsURLTokenAuthenticated
from django_rest_urltoken_auth.permissions import IsURLTokenAuthenticated
...
# viewsets.py
class ExampleViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = (IsURLTokenAuthenticated,)
queryset = Example.objects.all()
This view can now be accessed by adding ?token=<url_token> to the request url.
Optional configuration
- By default the url parameter used for the authentication token is
token. This can be adapted by overriding the settingDRF_URLTOKEN_PARAM. For example:
# settings.py
DRF_URLTOKEN_PARAM = "secret"
would lead to authentication the API using ?secret=<url_token> as url parameter.
- If you want to allow url token authentication on all requests methods
(not just read only methods
GET,HEAD,OPTIONS), then add to your settings:DRF_URLTOKEN_READ_ONLY=False
Running tests
For running the tests using pytest:
pip install pytest
pytest --pyargs django_rest_urltoken_auth.tests
Metadata
Release files for django-rest-urltoken-auth 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-rest-urltoken-auth-0.1.0.tar.gz | 5.0 kB | Without provenance | Details for django-rest-urltoken-auth-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_rest_urltoken_auth-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_rest_urltoken_auth-0.1.0-py3-none-any.whl |
Total release size: 13.8 kB
Release files / django-rest-urltoken-auth-0.1.0.tar.gz
| Download URL | django-rest-urltoken-auth-0.1.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb44729e5302afebe5ee1e0fa7640c0f6153adf0a7dbaf7a2749fc6f2f7b3d3c
|
|
BLAKE2b-256 checksum How to use checksums |
cbf3149d0f68250ce3105e457d31ad144e068a4c9e771b775456c03fb375fda1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / django_rest_urltoken_auth-0.1.0-py3-none-any.whl
| Download URL | django_rest_urltoken_auth-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc158698bacbf10186598f6de46f756c0ed9f1f98424e83719f218c5124a63da
|
|
BLAKE2b-256 checksum How to use checksums |
7c1d66832033ad4169eb5acaca46d992ecd22d1ee5baceffac36557cc896d1d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for django-rest-urltoken-auth 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.