Authentication library for aiohttp
Project description
aegis allows to protect endpoints and also provides authentication scoping.
Installation
pip install aegis
Simple Example
# examples/login_required.py
from aiohttp import web
from aegis import auth
from aegis.authenticators.jwt import JWTAuth
DATABASE = {
'david': {'id': 5, 'scopes': ('user',)}
}
class MyAuth(JWTAuth):
jwt_secret = "test"
async def authenticate(self, request: web.Request) -> dict:
payload = await request.json()
user = DATABASE.get(payload['username'])
return user
async def public(request):
return web.json_response({'hello': 'anonymous'})
@auth.login_required
async def protected(request):
return web.json_response({'hello': 'user'})
def create_app():
app = web.Application()
app.router.add_get('/public', public)
app.router.add_get('/protected', protected)
MyAuth.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 '{"username": "david"}'
{"access_token": "<access_token>"}
Get user
curl http://0.0.0.0:8080/me -H 'Authorization: Bearer <access_token>'
{"id": 5, "scopes": ["user"], "exp": 1553753859}
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.
Source Distribution
aegis-0.3.1.tar.gz
(7.7 kB
view hashes)
Built Distribution
aegis-0.3.1-py2.py3-none-any.whl
(19.5 kB
view hashes)
Close
Hashes for aegis-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e2d0ba272ec5f169a64cb4889abd8f6064b0eea3795c59083dbdf6c5b9827f |
|
MD5 | f738da4b9079d30aa4b978416bf4e858 |
|
BLAKE2b-256 | 72422349fbe0eb33c41c139d260aae76887efbe77863971c49c725a67c915014 |