diff options
author | Devaev Maxim <[email protected]> | 2020-08-30 21:00:35 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-08-30 21:00:35 +0300 |
commit | 2175338470899c03411e90641a36170b08d68d3e (patch) | |
tree | 6b412d6af4f62be8e742749e99543ee4d530e262 /kvmd | |
parent | a7de2184a7acd814c60452c136d5607941c8dad1 (diff) |
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/api/auth.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/kvmd/apps/kvmd/api/auth.py b/kvmd/apps/kvmd/api/auth.py index 7eafefd4..93d20ffe 100644 --- a/kvmd/apps/kvmd/api/auth.py +++ b/kvmd/apps/kvmd/api/auth.py @@ -43,18 +43,15 @@ _COOKIE_AUTH_TOKEN = "auth_token" async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, request: Request) -> None: if exposed.auth_required and auth_manager.is_auth_enabled(): - user = request.headers.get("X-KVMD-User", "") - passwd = request.headers.get("X-KVMD-Passwd", "") - token = request.cookies.get(_COOKIE_AUTH_TOKEN, "") - - if user: + if (user := request.headers.get("X-KVMD-User", "")): user = valid_user(user) + passwd = request.headers.get("X-KVMD-Passwd", "") set_request_auth_info(request, f"{user} (xhdr)") if not (await auth_manager.authorize(user, valid_passwd(passwd))): raise ForbiddenError() return - elif token: + elif (token := request.cookies.get(_COOKIE_AUTH_TOKEN, "")): user = auth_manager.check(valid_auth_token(token)) if not user: set_request_auth_info(request, "- (token)") |