Inigo Middleware
Project description
GraphQL Middleware
Explore the docs »
Homepage
·
View an example
·
Report Bug
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
Django
to pass in anInigoContext
object.
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,
JWT
header 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
Hashes for inigo_py-0.19.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea923b58a34b26f96977e0414de0d3a6fc7883596e27cdd6eca13e7e7b9fe571 |
|
MD5 | 4e667e6606a044c6381b05ca05aa0933 |
|
BLAKE2b-256 | 9e120ee079b865b63b75acc05041a22c86571f0674c835b10c1fd6cafb323971 |