Skip to main content

aiohttp-jwt

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!

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.

For advanced security facilities check aio-libs/aiohttp_security

License

MIT License

Metadata

Release files for aiohttp-jwt 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp-jwt 0.6.1
File Size Uploaded Provenance Actions
aiohttp_jwt-0.6.1.tar.gz 5.2 kB Without provenance Details for aiohttp_jwt-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-jwt 0.6.1
File Interpreter ABI Platform Actions
aiohttp_jwt-0.6.1-py3-none-any.whl Python 3 none any Details for aiohttp_jwt-0.6.1-py3-none-any.whl

Total release size: 11.0 kB

Release files / aiohttp_jwt-0.6.1.tar.gz

Download URL aiohttp_jwt-0.6.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6bfa0eeafa76bc164b8cc6961f2541226d977f59c5de58eaf5a191f899ee381e
BLAKE2b-256 checksum
How to use checksums
e72f1f17fb96577b6ff038034949df7ddcaf740c0780f1e699a157f0e387534e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / aiohttp_jwt-0.6.1-py3-none-any.whl

Download URL aiohttp_jwt-0.6.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e666d1b0ab02ced7cb8edc693b0da2850445e6a917d9b94943a80164e04f2689
BLAKE2b-256 checksum
How to use checksums
ccd2868c38f1bae7c3fac89ada750395eef821ddd9af8119c2a384db42182903
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for aiohttp-jwt 0.6.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page