1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-04 18:27:06 +02:00

[dashboard] Accept basic auth header

This commit is contained in:
Jesse Hills 2024-07-15 08:25:45 +12:00
parent 896af84acc
commit 59fe0323b1
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -107,6 +107,12 @@ def is_authenticated(handler: BaseHandler) -> bool:
return True
if settings.using_auth:
if auth_header := handler.request.headers.get("Authorization"):
assert isinstance(auth_header, str)
if auth_header.startswith("Basic "):
auth_decoded = base64.b64decode(auth_header[6:]).decode()
username, password = auth_decoded.split(":", 1)
return settings.check_password(username, password)
return handler.get_secure_cookie(AUTH_COOKIE_NAME) == COOKIE_AUTHENTICATED_YES
return True