Skip to main content

Authentication library for aiohttp

Project description

Python 3.6 pypi travis-badge coveralls codefactor grade code-style downloads

aegis allows to protect endpoints and also provides authentication scoping.


Installation

pip install aegis

Simple Example

from aiohttp import web
from aegis import login_required, JWTAuth


class JWTAuthenticator(JWTAuth):
    jwt_secret = "<secret>"

    async def authenticate(self, request: web.Request) -> dict:
        db = request.app["db"]
        credentials = await request.json()
        id_ = credentials["id"]
        user = db.get(id_)
        return user


@login_required
async def protected(request):
    return web.json_response({'hello': 'user'})


def create_app():
    app = web.Application()
    app["db"] = {
        5: {
            "name": "test"
        }
    }
    app.router.add_get('/protected', protected)

    JWTAuthenticator.setup(app)

    return app


if __name__ == "__main__":
    app = create_app()
    web.run_app(app)

Get access token

curl -X POST http://0.0.0.0:8080/auth -d '{"id": 5}'


{"access_token": "<access_token>"}

Get user

curl http://0.0.0.0:8080/protected -H 'Authorization: Bearer <access_token>'


{'hello': 'user'}

Test

git clone https://github.com/mgurdal/aegis.git
cd aegis
make cov

Requirements

  • Python >= 3.6
  • aiohttp
  • PyJWT

License

aegis is offered under the Apache 2 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 aegis, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size aegis-1.1.1-py3-none-any.whl (14.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aegis-1.1.1.tar.gz (9.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page