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.
Release files for aegis 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aegis-1.1.1.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aegis-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.1 kB
Release files / aegis-1.1.1.tar.gz
| Download URL | aegis-1.1.1.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c057d0a84476d57211ec29faf95cbc23df293d1a87f308ed1ba765b38b2df5c9
|
|
BLAKE2b-256 checksum How to use checksums |
4c2c2c2a58f331adc2dc09f506d755fd4d07bb3c9f3d1d1c365491e00aabf399
|
| 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Release files / aegis-1.1.1-py3-none-any.whl
| Download URL | aegis-1.1.1-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6db77d0e4373b152f23532738df07b76fb6fbdde169b76cc2794576edc9facc0
|
|
BLAKE2b-256 checksum How to use checksums |
50fbbcc5f2b3e7da0ab879c3ff9b778ae2ea8da0196adc3a89b94525ec4be3a3
|
| 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|