An incredibly simple HTTP basic auth implementation for Aiohttp.
Project description
Aiohttp middleware for simple http basic auth protection for some urls.
Works with Python >= 3.6.
Works with UTF-8 🖖
Installation
pip install aiohttp-basicauth-middleware
Usage
app = web.Application(loop=loop)
app.router.add_route('GET', '/hello', handler_a)
app.router.add_route('GET', '/admin/hello', handler_b)
app.middlewares.append(
basic_auth_middleware(
('/admin',),
{'user': 'password'},
)
)
basic_auth_middleware has 3 params:
list of protected urls. For example [‘/admin’] will match with /admin/user, but will not match with /user/admin.
auth dict – a dict with pairs: login-password.
strategy (optional) for password comparision. For example you can store hashed password in auth_dict. See aiohttp_basicauth_middleware.strategy.BaseStrategy and example.strategy for more information.
Example with md5 password hashing:
app = web.Application(loop=loop)
app.router.add_route('GET', '/hello', handler_a)
app.router.add_route('GET', '/admin/hello', handler_b)
app.middlewares.append(
basic_auth_middleware(
('/admin',),
{'user': '5f4dcc3b5aa765d61d8327deb882cf99'},
lambda x: hashlib.md5(bytes(x, encoding='utf-8')).hexdigest(),
)
)
/admin/… will be accessed by the same login+password pair (‘user’, ‘password’).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for aiohttp-basicauth-middleware-1.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d21dadf4a839be6ceddff0fbce74f678b5e4c3e4a6177d431c69b662f77922d3 |
|
MD5 | 59f4562e99d4d9636d013e7c555cc05f |
|
BLAKE2b-256 | 0582a4dafcf373255b764e23d590c5aa35938e8b54d350c760fe29f88706bbb1 |