Inigo Middleware
Project description
Inigo integration for Django and Graphene
Quickstart
Install inigo middleware
pip install inigo-py
Django Settings
MIDDLEWARE = [
...
'inigo_py.DjangoMiddleware',
]
INIGO = {
'DEBUG': False,
'TOKEN': 'Your Inigo service token',
'PATH': '/graphql',
'JWT': 'authorization',
'GRAPHENE_SCHEMA': 'app.schema.schema'
# 'SCHEMA_PATH': './schema.graphql',
}
Configuration options
DEBUG
Optional. Default: False
If not provided, Django DEBUG setting is used.
TOKEN
Required. Obtain a service token from app.inigo.io
GRAPHENE_SCHEMA
Optional. The path to graphene schema instance. If not provided, InigoMiddleware will try to pick it up from GRAPHENE.SCHEMA settings.
SCHEMA_PATH
Optional. The path to graphql schema file.
PATH
Optional. Default: /graphql.
Your graphql route path.
JWT
Optional. Default: authorization.
Name of your authorization header with jwt as a value. See Authorization for more details.
Authentication
Passing Authentication using JWT header
- Configure and apply your
service.yml
kind: Service
name: <service_name>
spec:
path_user_id: jwt.user_name
path_user_profile: jwt.user_profile
path_user_role: jwt.user_roles
- Provide name of the header into Djang configuration
INIGO = {
'JWT': 'authorization'
}
NOTE. Payload of the decoded jwt should match with the provided above configuration.
Passing Authentication using Context
- Configure and apply your
service.yml
kind: Service
name: <service_name>
spec:
path_user_id: ctx.user_name
path_user_profile: ctx.user_profile
path_user_role: ctx.user_roles
- Configure
Djangoto pass in anInigoContextobject.
from inigo_py import InigoContext
# define middleware to pass authentication via ctx
def auth(get_response):
def middleware(request):
request.inigo = InigoContext()
request.inigo.auth = {
'user_name': 'me',
'user_profile': 'guest',
'user_roles': [],
}
return get_response(request)
return middleware
# add middleware to Django settings. Make sure to add it before `inigo_py.DjangoMiddleware` as it's providing info required for correct request processing.
MIDDLEWARE = [
...
'middleware.auth',
'inigo_py.DjangoMiddleware',
]
Note: if auth object provided on request,
JWTheader is not used
Logging blocked requests
# define middleware to check the request status after the request was processed by Inigo.
def log_inigo_blocked_requests(get_response):
def middleware(request):
resp = get_response(request)
# NOTE. accessing value from 'request' object
print(f'request is blocked: { request.inigo.blocked }')
return resp
return middleware
# add middleware to Django settings. Make sure to add it before `inigo_py.DjangoMiddleware` as status is available after `get_response` call.
MIDDLEWARE = [
...
'middleware.log_inigo_blocked_requests',
'inigo_py.DjangoMiddleware',
]
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
License
Distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inigo_py-0.22.0.tar.gz.
File metadata
- Download URL: inigo_py-0.22.0.tar.gz
- Upload date:
- Size: 71.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cdf174eb589d2ea23ad7480128e099045e481d19204ee59004324cec58f5936
|
|
| MD5 |
cab3647e5e7aac25eee40fb91206e8a0
|
|
| BLAKE2b-256 |
63cc072544838a168b858c765a2df2d6afe27e57b6f2c2e56b5b5ae36783fb66
|
File details
Details for the file inigo_py-0.22.0-py3-none-any.whl.
File metadata
- Download URL: inigo_py-0.22.0-py3-none-any.whl
- Upload date:
- Size: 72.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f895584c7479f3347ca128f0fe119e9861f53eb565950f355e3a9b55a8f85fe4
|
|
| MD5 |
53d66a971252128894d41ff0fbae12f9
|
|
| BLAKE2b-256 |
25cb5a85d2e706cd381b9ebf626e806daf4634d83218f570036fbef328abb1eb
|