0
votes

I'm trying to connect to a kusto cluster I created in azure from Visual Studio 2019, .NET Core 3.1

I'm following this link: https://docs.microsoft.com/en-us/azure/data-explorer/kusto/api/connection-strings/kusto

This is what I'm doing:

var azureServiceTokenProvider = new AzureServiceTokenProvider();
var accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(clusterUri);
var managedIdentity = "<managed identity>";

var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(clusterUri))
                                       .WithAadManagedIdentity(managedIdentity);

But I keep getting this error:

"Exception Message: Tried the following 3 methods to get an access token, but none of them worked."

What am I doing wrong? Is there a simple way to connect to the cluster?

1

1 Answers

0
votes

Judging by the exception text, you are not getting it from Kusto SDK. Can you debug to see what line in your code is throwing this error? If you are using managed identities and the identity you need is available in your environment, you do not need the first two lines; all you need is the managed identity id.

Alternatively, if you wish to perform the auth yourself, you need to follow the "token provider" pattern and use the AzureServiceTokenProvider's GetAccessTokenAsync method:

Func<string> tokenProviderCallback; // User-defined method to retrieve the access token

// Recommended syntax
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(serviceUri)
    .WithAadTokenProviderAuthentication(tokenProviderCallback);