This commit is contained in:
parent
cc621ce33d
commit
84b5d45f1c
@ -7,3 +7,6 @@ logging.basicConfig(
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from .app import Application as BaseApplication
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import base64
|
||||
import dataset
|
||||
from aiohttp import web
|
||||
|
||||
@ -20,22 +20,22 @@ class BaseApplication(web.Application):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
username=None,
|
||||
password=None,
|
||||
basic_username=None,
|
||||
basic_password=None,
|
||||
cookie_name=None,
|
||||
session=None,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
self.cookie_name = cookie_name or str(uuid.uuid4())
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.basic_username = basic_username
|
||||
self.basic_password = basic_password
|
||||
self.session = session or {}
|
||||
middlewares = kwargs.pop("middlewares", [])
|
||||
middlewares.append(self.request_middleware)
|
||||
middlewares.append(self.base64_auth_middleware)
|
||||
middlewares.append(self.session_middleware)
|
||||
super().__init__(*args, **kwargs)
|
||||
super().__init__(middlewares=middlewares,*args, **kwargs)
|
||||
|
||||
def run(self, *args, **kwargs):
|
||||
web.run_app(self, *args, **kwargs)
|
||||
@ -44,7 +44,7 @@ class BaseApplication(web.Application):
|
||||
return self.username == username and self.password == password
|
||||
|
||||
@web.middleware
|
||||
async def base64_auth_middleware(request, handler):
|
||||
async def base64_auth_middleware(self, request, handler):
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not self.username:
|
||||
return await handler(request)
|
||||
|
Loading…
Reference in New Issue
Block a user