diff --git a/moonraker/components/authorization.py b/moonraker/components/authorization.py index 5861351..a5b0d53 100644 --- a/moonraker/components/authorization.py +++ b/moonraker/components/authorization.py @@ -71,6 +71,7 @@ class Authorization: def __init__(self, config: ConfigHelper) -> None: self.server = config.get_server() self.login_timeout = config.getint('login_timeout', 90) + self.force_logins = config.getboolean('force_logins', False) database: DBComp = self.server.lookup_component('database') database.register_local_namespace('authorized_users', forbidden=True) self.users = database.wrap_namespace('authorized_users') @@ -533,6 +534,11 @@ class Authorization: if key and key == self.api_key: return self.users[API_USER] + # If the force_logins option is enabled and at least one + # user is created this is an unauthorized request + if self.force_logins and len(self.users) > 1: + raise HTTPError(401, "Unauthorized") + # Check if IP is trusted trusted_user = self._check_trusted_connection(ip) if trusted_user is not None: