Skip to main content

Django REST app to allow authentication with url tokens

Project description

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

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

django-rest-urltoken-auth-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-rest-urltoken-auth-0.1.0.tar.gz.

File metadata

  • Download URL: django-rest-urltoken-auth-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-rest-urltoken-auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb44729e5302afebe5ee1e0fa7640c0f6153adf0a7dbaf7a2749fc6f2f7b3d3c
MD5 965c00a9b63d11df2b4ccc26ef55db95
BLAKE2b-256 cbf3149d0f68250ce3105e457d31ad144e068a4c9e771b775456c03fb375fda1

See more details on using hashes here.

File details

Details for the file django_rest_urltoken_auth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_rest_urltoken_auth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_rest_urltoken_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc158698bacbf10186598f6de46f756c0ed9f1f98424e83719f218c5124a63da
MD5 336b2dbf1670a0bfc23fb80edc5cfef5
BLAKE2b-256 7c1d66832033ad4169eb5acaca46d992ecd22d1ee5baceffac36557cc896d1d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page