def test_interactive_login(): if not TEST_INTERACTIVE_AUTH: print(" *** Skipped interactive login Test ***") return kcsb = KustoConnectionStringBuilder.with_interactive_login(KUSTO_TEST_URI) aad_helper = _AadHelper(kcsb) # should prompt header = aad_helper.acquire_authorization_header() assert header is not None # should not prompt header = aad_helper.acquire_authorization_header() assert header is not None
def generate_connection_string( cls, cluster_url: str, authentication_mode: AuthenticationModeOptions ) -> KustoConnectionStringBuilder: """ Generates Kusto Connection String based on given Authentication Mode. :param cluster_url: Cluster to connect to. :param authentication_mode: User Authentication Mode, Options: (UserPrompt|ManagedIdentity|AppKey|AppCertificate) :return: A connection string to be used when creating a Client """ # Learn More: For additional information on how to authorize users and apps in Kusto, # see: https://docs.microsoft.com/azure/data-explorer/manage-database-permissions if authentication_mode == AuthenticationModeOptions.UserPrompt.name: # Prompt user for credentials return KustoConnectionStringBuilder.with_interactive_login( cluster_url) elif authentication_mode == AuthenticationModeOptions.ManagedIdentity.name: # Authenticate using a System-Assigned managed identity provided to an azure service, or using a User-Assigned managed identity. # For more information, see https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview return cls.create_managed_identity_connection_string( cluster_url) elif authentication_mode == AuthenticationModeOptions.AppKey.name: # Learn More: For information about how to procure an AAD Application, # see: https://docs.microsoft.com/azure/data-explorer/provision-azure-ad-app # TODO (config - optional): App ID & tenant, and App Key to authenticate with return KustoConnectionStringBuilder.with_aad_application_key_authentication( cluster_url, os.environ.get("APP_ID"), os.environ.get("APP_KEY"), os.environ.get("APP_TENANT")) elif authentication_mode == AuthenticationModeOptions.AppCertificate.name: return cls.create_application_certificate_connection_string( cluster_url) else: Utils.error_handler( f"Authentication mode '{authentication_mode}' is not supported" )
def proxy_kcsb(request) -> Tuple[KustoConnectionStringBuilder, bool]: cluster = KustoClientTestsMixin.HOST user = "******" password = "******" authority_id = "13456" uuid = "11111111-1111-1111-1111-111111111111" key = "key of application" token = "The app hardest token ever" return { "user_password": (KustoConnectionStringBuilder.with_aad_user_password_authentication( cluster, user, password, authority_id), True), "application_key": (KustoConnectionStringBuilder.with_aad_application_key_authentication( cluster, uuid, key, "microsoft.com"), True), "application_token": (KustoConnectionStringBuilder. with_aad_application_token_authentication( cluster, application_token=token), False), "device": (KustoConnectionStringBuilder.with_aad_device_authentication(cluster), True), "user_token": (KustoConnectionStringBuilder.with_aad_user_token_authentication( cluster, user_token=token), False), "managed_identity": (KustoConnectionStringBuilder. with_aad_managed_service_identity_authentication(cluster), False), "token_provider": (KustoConnectionStringBuilder.with_token_provider( cluster, lambda x: x), False), "async_token_provider": (KustoConnectionStringBuilder.with_async_token_provider( cluster, lambda x: x), False), "az_cli": (KustoConnectionStringBuilder.with_az_cli_authentication(cluster), True), "interactive_login": (KustoConnectionStringBuilder.with_interactive_login(cluster), True), }[request.param]
def engine_kcsb_from_env(cls, app_insights=False) -> KustoConnectionStringBuilder: engine = cls.engine_cs if not app_insights else cls.ai_engine_cs if all([cls.app_id, cls.app_key, cls.auth_id]): return KustoConnectionStringBuilder.with_aad_application_key_authentication(engine, cls.app_id, cls.app_key, cls.auth_id) else: return KustoConnectionStringBuilder.with_interactive_login(engine)