summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-08-30 21:12:13 +0300
committerDevaev Maxim <[email protected]>2020-08-30 21:12:13 +0300
commit02e207347b437bb4127ef0d1c16aa43a29a42a59 (patch)
tree874f3ef4a51390b55e19c83530635e1e425ad48d /kvmd
parent2175338470899c03411e90641a36170b08d68d3e (diff)
supported Authorization header
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/api/auth.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/kvmd/apps/kvmd/api/auth.py b/kvmd/apps/kvmd/api/auth.py
index 93d20ffe..cdbeb0a6 100644
--- a/kvmd/apps/kvmd/api/auth.py
+++ b/kvmd/apps/kvmd/api/auth.py
@@ -20,6 +20,8 @@
# ========================================================================== #
+import base64
+
from aiohttp.web import Request
from aiohttp.web import Response
@@ -59,6 +61,18 @@ async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, re
set_request_auth_info(request, f"{user} (token)")
return
+ elif (basic_auth := request.headers.get("Authorization", "")):
+ if basic_auth[:6].lower() == "basic ":
+ try:
+ (user, passwd) = base64.b64decode(basic_auth[6:]).decode("utf-8").split(":")
+ except Exception:
+ raise UnauthorizedError()
+ user = valid_user(user)
+ set_request_auth_info(request, f"{user} (basic)")
+ if not (await auth_manager.authorize(user, valid_passwd(passwd))):
+ raise ForbiddenError()
+ return
+
raise UnauthorizedError()