aiohttp-basicauth-1.0.0
توضیحات
HTTP basic authentication middleware for aiohttp 3.0+
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | aiohttp-basicauth-1.0.0 |
| نام | aiohttp-basicauth |
| نسخه کتابخانه | 1.0.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Roman Snegirev |
| ایمیل نویسنده | snegiryev@gmail.com |
| آدرس صفحه اصلی | https://github.com/romis2012/aiohttp-basicauth |
| آدرس اینترنتی | https://pypi.org/project/aiohttp-basicauth/ |
| مجوز | Apache 2 |
## aiohttp-basicauth
[](https://travis-ci.com/github/romis2012/aiohttp-basicauth)
[](https://coveralls.io/github/romis2012/aiohttp-basicauth?branch=master)
[](https://badge.fury.io/py/aiohttp-basicauth)
HTTP basic authentication middleware for aiohttp 3.0+.
Inspired by [Flask-BasicAuth](https://github.com/jpvanhal/flask-basicauth).
## Requirements
- Python >= 3.5.3
- aiohttp >= 3.0
## Installation
```
pip install aiohttp_basicauth
```
## Simple usage
```python
from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware
auth = BasicAuthMiddleware(username='user', password='password')
app = web.Application(middlewares=[auth])
web.run_app(app, host='127.0.0.1', port=80)
```
## Protect specific view(s)
```python
from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware
auth = BasicAuthMiddleware(username='user', password='password', force=False)
async def public_view(request):
return web.Response(text='Public view')
@auth.required
async def secret_view(request):
return web.Response(text='Secret view')
app = web.Application(middlewares=[auth])
app.router.add_route('GET', '/public', public_view)
app.router.add_route('GET', '/secret', secret_view)
web.run_app(app, host='127.0.0.1', port=80)
```
## Advanced usage
You can override ```check_credentials``` method to implement more complex user verification logic:
```python
from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware
class CustomBasicAuth(BasicAuthMiddleware):
async def check_credentials(self, username, password, request):
# here, for example, you can search user in the database by passed `username` and `password`, etc.
return username == 'user' and password == 'password'
auth = CustomBasicAuth()
app = web.Application(middlewares=[auth])
web.run_app(app, host='127.0.0.1', port=80)
```
نیازمندی
| مقدار | نام |
|---|---|
| >=3.0 | aiohttp |
نحوه نصب
نصب پکیج whl aiohttp-basicauth-1.0.0:
pip install aiohttp-basicauth-1.0.0.whl
نصب پکیج tar.gz aiohttp-basicauth-1.0.0:
pip install aiohttp-basicauth-1.0.0.tar.gz