Skip to main content

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

  1. Add "django_rest_urltoken_auth" to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        ...
        'django_rest_urltoken_auth',
    ]
    
  2. Run python manage.py migrate to 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 setting DRF_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)

Source distribution for django-rest-urltoken-auth 0.1.0
File Size Uploaded
django-rest-urltoken-auth-0.1.0.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-rest-urltoken-auth 0.1.0
File Interpreter ABI Platform
django_rest_urltoken_auth-0.1.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page