diff --git a/azure-kusto-data/azure/kusto/data/kcsb.py b/azure-kusto-data/azure/kusto/data/kcsb.py index 903afc2a..f0862ffe 100644 --- a/azure-kusto-data/azure/kusto/data/kcsb.py +++ b/azure-kusto-data/azure/kusto/data/kcsb.py @@ -132,6 +132,7 @@ def __init__(self, connection_string: str): self._token_provider = None self._async_token_provider = None self.is_token_credential_auth = False + self.is_device_login_auth = False self.credential: Optional[Any] = None self.credential_from_login_endpoint: Optional[Any] = None if connection_string is not None and "=" not in connection_string.partition(";")[0]: @@ -339,6 +340,7 @@ def with_aad_device_authentication( - ``expires_on`` (datetime.datetime) the UTC time at which the code will expire """ kcsb = cls(connection_string) + kcsb.is_device_login_auth = True kcsb[kcsb.ValidKeywords.aad_federated_security] = True kcsb[kcsb.ValidKeywords.authority_id] = authority_id kcsb.device_callback = callback @@ -482,6 +484,19 @@ def with_azure_token_credential( return kcsb + @classmethod + def with_no_authentication(cls, connection_string: str) -> "KustoConnectionStringBuilder": + """ + Create a KustoConnectionStringBuilder that uses no authentication. + :param connection_string: Kusto's connection string should be of the format: http://.kusto.windows.net + """ + if not connection_string.startswith("http://"): + raise ValueError("Connection string must start with http://") + kcsb = cls(connection_string) + kcsb[kcsb.ValidKeywords.aad_federated_security] = False + + return kcsb + @property def data_source(self) -> Optional[str]: """The URI specifying the Kusto service endpoint. diff --git a/azure-kusto-data/azure/kusto/data/security.py b/azure-kusto-data/azure/kusto/data/security.py index b9ff66ac..56b82507 100644 --- a/azure-kusto-data/azure/kusto/data/security.py +++ b/azure-kusto-data/azure/kusto/data/security.py @@ -72,8 +72,10 @@ def __init__(self, kcsb: "KustoConnectionStringBuilder", is_async: bool): credential=kcsb.credential, credential_from_login_endpoint=kcsb.credential_from_login_endpoint, ) - else: # TODO - next breaking change - remove this as default, make no auth the default + elif kcsb.is_device_login_auth: self.token_provider = DeviceLoginTokenProvider(self.kusto_uri, kcsb.authority_id, kcsb.device_callback, is_async=is_async) + else: + self.token_provider = InteractiveLoginTokenProvider(self.kusto_uri, kcsb.authority_id, kcsb.login_hint, kcsb.domain_hint, is_async=is_async) def acquire_authorization_header(self): try: diff --git a/azure-kusto-data/tests/test_kusto_connection_string_builder.py b/azure-kusto-data/tests/test_kusto_connection_string_builder.py index c65eba82..afa5a2a6 100644 --- a/azure-kusto-data/tests/test_kusto_connection_string_builder.py +++ b/azure-kusto-data/tests/test_kusto_connection_string_builder.py @@ -3,8 +3,11 @@ import unittest from uuid import uuid4 +import pytest from azure.kusto.data import KustoConnectionStringBuilder, KustoClient +local_emulator = False + class KustoConnectionStringBuilderTests(unittest.TestCase): """Tests class for KustoConnectionStringBuilder.""" @@ -326,6 +329,12 @@ async def async_token_provider(): finally: assert exception_occurred + @pytest.mark.skipif(not local_emulator, reason="requires local emulator") + def test_no_authentication(self): + kscb = KustoConnectionStringBuilder.with_no_authentication("http://localhost:8080") + assert kscb.data_source == "http://localhost:8080" + assert kscb.aad_federated_security is False + def test_initial_catalog_default(self): kcsb = KustoConnectionStringBuilder.with_az_cli_authentication("https://help.kusto.windows.net") assert kcsb.data_source == "https://help.kusto.windows.net"