An incredibly simple HTTP basic auth implementation for Aiohttp.
Project description
# aiohttp-basicauth-middleware
[![Build Status](https://travis-ci.org/bugov/aiohttp-basicauth-middleware.svg?branch=master)](https://travis-ci.org/bugov/aiohttp-basicauth-middleware)
Aiohttp middleware for simple http basic
auth protection for some urls.
Works with Python >= 3.5.
Works with UTF-8 🖖
## Installation
pip install aiohttp-basicauth-middleware
## Usage
```python
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:
1. list of protected urls. For example `['/admin']` will match
with `/admin/user`, but will not match with `/user/admin`.
2. auth dict – a dict with pairs: login-password.
3. strategy (optional) for password comparision. For example you can
store hashed password in `auth_dict`.
Example with md5 password hashing:
```python
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').
[![Build Status](https://travis-ci.org/bugov/aiohttp-basicauth-middleware.svg?branch=master)](https://travis-ci.org/bugov/aiohttp-basicauth-middleware)
Aiohttp middleware for simple http basic
auth protection for some urls.
Works with Python >= 3.5.
Works with UTF-8 🖖
## Installation
pip install aiohttp-basicauth-middleware
## Usage
```python
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:
1. list of protected urls. For example `['/admin']` will match
with `/admin/user`, but will not match with `/user/admin`.
2. auth dict – a dict with pairs: login-password.
3. strategy (optional) for password comparision. For example you can
store hashed password in `auth_dict`.
Example with md5 password hashing:
```python
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
Close
Hashes for aiohttp-basicauth-middleware-1.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88e471b3a05c573e5b21d10365758dbd08334411f12ac0fee15a4bf3a36f97d2 |
|
MD5 | 72b61ebcaaa9e9aebce111be03184aea |
|
BLAKE2b-256 | 67593f59a4f34e5290818455f71e40061f1ec6ba5b9ff3ad7d049433be4a6ccd |