===============
A stateless authentication backend intended to temporarily expose
protected resources.
|Build Status| |Code Coverage|
Why?
----
The motivation for this package comes from a frequent project
requirement to directly download served by the API in formats like CSV
or Excel within the context of a single-page-application.
Within this context, authentication cannot be achieved using HTTP
Headers, as the resource is accessed directly through a URL via an
``<a>`` tag. Therefore, a temporary signature passed in the query string
must be used to authenticate the request.
This package uses Django's cryptographic signing to produce a
short-lived signature. It provides a view used to produce the signature
and a DRF authentication backend.
Is this secure?
---------------
Use this backend with caution and sparingly. Anyone with a copy of the
signed URL will be able to access a protected resource, so keep the
expiry time short (see settings), and ensure that the Django
``SECRET_KEY`` setting is kept private.
Requirements
------------
- Python 2.7 / 3.6
- Django 1.8, 1.9, 1.10, 1.11
- Django REST Framework 3.6, 3.7
Installation
------------
``pip install drf-signed-auth``
Quick start
-----------
Register the SignUrlView in ``urls.py``
.. code:: python
# urls.py
from django.conf.urls import url
from drf_signed_auth.views import SignUrlView
urlpatterns = [
...
url(r'^sign-url/$', SignUrlView.as_view(), name='sign-url'),
...
]
Use the authentication backend on the view you wish to expose.
.. code:: python
# views.py
from drf_signed_auth.authentication import SignedURLAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
class MyCSVView(APIView):
...
authentication_classes = [SignedURLAuthentication]
permission_classes = [IsAuthenticated]
...
Usage
-----
Obtain the signature by making a POST request to the Sign URL endpoint,
and provide the ``url`` of the endpoint you wish to access. This can be
a relative or absolute path.
Example
~~~~~~~
::
# Request
POST /sign-url HTTP/1.1
HOST your.api.host
Content-Type: application/json
{"url": "/path"}
# Response
http://your.api.host/path?sig=xxxxxxxxxxxxxxx
The returned URL will be valid for the time specified by the
``SIGNED_URL_TTL``.
Settings
--------
The following settings may be configured in your project's
``settings.py``
+------+------+------+
| Sett | Desc | Defa |
| ing | ript | ult |
| | ion | |
+======+======+======+
| ``SI | The | ``30 |
| GNED | time | `` |
| _URL | in | (sec |
| _TTL | seco | onds |
| `` | nds | ) |
| | for | |
| | whic | |
| | h | |
| | the | |
| | sign | |
| | atur | |
| | e | |
| | is | |
| | vali | |
| | d | |
+------+------+------+
| ``SI | The | ``si |
| GNED | quer | g`` |
| _URL | ystr | |
| _QUE | ing | |
| RY_P | vari | |
| ARAM | able | |
| `` | name | |
+------+------+------+
| ``SI | Perm | ``[r |
| GNED | issi | est_ |
| _URL | on | fram |
| _PER | clas | ewor |
| MISS | ses | k.pe |
| ION_ | on | rmis |
| CLAS | the | sion |
| SES` | sign | s.Is |
| ` | ed | Auth |
| | URL | enti |
| | view | cate |
| | | d]`` |
+------+------+------+
.. |Build Status| image:: https://travis-ci.org/marcgibbons/drf_signed_auth.png?branch=master
:target: https://travis-ci.org/marcgibbons/drf_signed_auth
.. |Code Coverage| image:: https://codecov.io/gh/marcgibbons/drf_signed_auth/branch/master/graph/badge.svg
:target: https://codecov.io/gh/marcgibbons/drf_signed_auth
Metadata
Release files for drf-signed-auth 0.1.1
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 |
|---|---|---|---|---|
| drf_signed_auth-0.1.1.tar.gz | 5.7 kB | Without provenance | Details for drf_signed_auth-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_signed_auth-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for drf_signed_auth-0.1.1-py3-none-any.whl |
Total release size: 18.8 kB
Release files / drf_signed_auth-0.1.1.tar.gz
| Download URL | drf_signed_auth-0.1.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9cfdd0facbb0f6c4772e62feebabb521ccf8c603190619ce94441e8b32915298
|
|
BLAKE2b-256 checksum How to use checksums |
44aa14bf21a401d36bac6511a75e9128cb6ea6ac9271475d7904af50adef2bc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / drf_signed_auth-0.1.1-py3-none-any.whl
| Download URL | drf_signed_auth-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b36f6e2fa59dcba72ae7f37b4cdca46bfe6dcb96859a4c57e549bd6e92e2a28
|
|
BLAKE2b-256 checksum How to use checksums |
6554fc71d580c985dbcf9439146c64028ebefdefaa31f85857062c30fbe55b54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for drf-signed-auth 0.1.1
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.