aiohttp middleware for working with JWT
Project description
aiohttp-jwt
The library provides aiohttp middleware and helper utils for working with JSON web tokens.
- Works on Python3.5+
- MIT License
- Latest docs TBD
- Contributions are highly welcome!
Requirements
Install
$ pip install aiohttp_jwt
Simple Usage
server.py
import jwt
from aiohttp import web
from aiohttp_jwt import JWTMiddleware
sharable_secret = 'secret'
async def protected_handler(request):
return web.json_response({'user': request['payload']})
app = web.Application(
middlewares=[
JWTMiddleware(sharable_secret),
]
)
app.router.add_get('/protected', protected_handler)
if __name__ == '__main__':
web.run_app(app)
client.py
import asyncio
import aiohttp
import async_timeout
async def fetch(session, url, headers=None):
async with async_timeout.timeout(10):
async with session.get(url, headers=headers) as response:
return await response.json()
async def main():
async with aiohttp.ClientSession() as session:
response = await fetch(
session,
'http://localhost:8080/protected',
headers={'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRlc3QifQ.pyNsXX_vNsUvdt6xu13F1Gs1zGELT4Va8a38eG5svBA'})
print(response)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Examples
Credits
This module inspired by official auth0/express-jwt middleware and express-jwt-permissions extension.
Related packages
For advanced security facilities check aio-libs/aiohttp_security
License
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 aiohttp_jwt-0.6.1.tar.gz.
File metadata
- Download URL: aiohttp_jwt-0.6.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bfa0eeafa76bc164b8cc6961f2541226d977f59c5de58eaf5a191f899ee381e
|
|
| MD5 |
e7824abec06325eb4275f197db22515d
|
|
| BLAKE2b-256 |
e72f1f17fb96577b6ff038034949df7ddcaf740c0780f1e699a157f0e387534e
|
File details
Details for the file aiohttp_jwt-0.6.1-py3-none-any.whl.
File metadata
- Download URL: aiohttp_jwt-0.6.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e666d1b0ab02ced7cb8edc693b0da2850445e6a917d9b94943a80164e04f2689
|
|
| MD5 |
ff94a4ad6a2e032ce15dadfd8205a1ca
|
|
| BLAKE2b-256 |
ccd2868c38f1bae7c3fac89ada750395eef821ddd9af8119c2a384db42182903
|