Skip to main content

aiohttp middleware for working with JWT

Project description


Downloads Build Status codecov

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!



$ pip install aiohttp_jwt

Simple Usage

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(

app.router.add_get('/protected', protected_handler)

if __name__ == '__main__':

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(
            headers={'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRlc3QifQ.pyNsXX_vNsUvdt6xu13F1Gs1zGELT4Va8a38eG5svBA'})

loop = asyncio.get_event_loop()



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


MIT License

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aiohttp-jwt, version 0.6.1
Filename, size File type Python version Upload date Hashes
Filename, size aiohttp_jwt-0.6.1-py3-none-any.whl (5.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiohttp_jwt-0.6.1.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page