Skip to content

allow client creation without authorization #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,15 @@ def __init__(
self.opener = urllib.request.build_opener(*handlers, https_handler)
urllib.request.install_opener(self.opener)

if login or password:
if login and not password:
raise ClientError("Unable to log in: no password provided for '{}'".format(login))
if password and not login:
raise ClientError("Unable to log in: password provided but no username/email")
if login and not password:
raise ClientError("Unable to log in: no password provided for '{}'".format(login))
if password and not login:
raise ClientError("Unable to log in: password provided but no username/email")

if login and password:
self._auth_params = {"login": login, "password": password}
if not self._auth_session:
self.login(login, password)

else:
if login and password:
self._auth_params = {"login": login, "password": password}
if not self._auth_session:
raise ClientError("Unable to log in: no auth token provided for login")
self.login(login, password)

def setup_logging(self):
"""Setup Mergin Maps client logging."""
Expand Down
15 changes: 15 additions & 0 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2871,3 +2871,18 @@ def server_config(self):

with pytest.raises(ClientError, match="The requested URL was not found on the server"):
mc.send_logs(logs_path)


def test_mc_without_login():

# client without login should be able to access server config
mc = MerginClient(SERVER_URL)
config = mc.server_config()
assert config
assert isinstance(config, dict)
assert "server_configured" in config
assert config["server_configured"]

# without login should not be able to access workspaces
with pytest.raises(ClientError, match="Authentication information is missing or invalid."):
mc.workspaces_list()