This release is a pre-release and may not be stable for production use.
API MIDDLEWARE
La aplicacion utiliza la libreria PYJWT para agregar un token a cada request y a cada response mediante un middleware personalizado.
Instalacion
Agregar a la lista de aplicaciones.
INSTALLED_APPS = [
...
'authorized'
]
Agregar el middleware al inicio de la lista.
MIDDLEWARE = [
'authorized.middleware.APIAuthRequestMiddleware',
...
]
Agregar las variables *Requerido
En el archivo settings.py agregar las variables.
APP_NAME = 'Awesome App'
IGNORED_PATHS = []
En el archivo docker-compose.yml
service:
...
environment:
- APP_KEY=secret
Aplicar las migraciones del middleware.
$ python manage.py migrate authorized
Uso
Requests
Para que el middleware funcione se necesita agregar el header
'Application-Token':token
Para evitar hacerlo se creo una “mascara” de la libreria python requests que agrega el token automaticamente, sin alterar su funcionalidad. Importar el modulo.
from authorized import api_request
hacer los request de forma normal, ie.
api_request.get('url', params)
Todos los metodos de python requests estan disponibles en el modulo api_request:
get
post
put
patch
delete
options
head
Para peticiones a aplicaciones externas se debe especificar en cada metodo el parametro is_external=True, por defecto el valor es False, esto previene que el middleware evalue que la respuesta provenga de una fuente confiable.
api_request.get('https://jsonplaceholder.typicode.com/posts/1', is_external=True)
Informacion adicional sobre python requests consultar Aqui
Correr Tests
Para ejecutar los tests de la aplicacion authorized, ejecutar el comando.
python manage.py test authorized
Metadata
Release files for django-api-middleware 0.0.6b1
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-api-middleware-0.0.6b1.tar.gz | 10.6 kB | Without provenance | Details for django-api-middleware-0.0.6b1.tar.gz |
Release files / django-api-middleware-0.0.6b1.tar.gz
| Download URL | django-api-middleware-0.0.6b1.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a044e7ce5fad5e1a6728dcc81878dd43a81a4a4e4e40731ba11bc0118965b0b3
|
|
BLAKE2b-256 checksum How to use checksums |
78c4e124b421e929afb93b53e7730418122875e438b2ad26b45e4e7f4a3381da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.6
|
Security for django-api-middleware 0.0.6b1
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.