Azure Data Explorer - Kusto query: unauthorized error querying from an Azure AD application

Valeria Naldi 65 Reputation points
I would like to create a web application where to run ADX queries
I followed instruction here to create and register the AAD application:

and this is the code:
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(<ADX cluster uri/database>);
        kustoConnectionStringBuilder.WithAadApplicationKeyAuthentication(<ApplicationId>, <Application Secret>, <TenantID>);
        var kustoClient = KustoClientFactory.CreateCslQueryProvider(kustoConnectionStringBuilder.ConnectionString);

        var query = "AdtPropertyEvents\r\n| count";
        var reader = kustoClient.ExecuteQuery(query);

I received the below error. Any suggestion to fix the problem? 

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
431 questions
{count} votes

Accepted answer
  1. KranthiPakala-MSFT 45,902 Reputation points Microsoft Employee

    Hi @Valeria Naldi ,

    Welcome to Microsoft Q&A forum and thanks for reaching out here.

    Looking at the error message 401-Unauthorized, it seems like your Azure AD App doesn't have permission to access the ADX cluster.

    Could you please make follow the below series of steps to ensure that your Azure AD App has permission to access your ADX cluster.

    User's image

    Please note that, after creating the application registration, there may be a several minute delay until Azure Data Explorer can reference it. If, when executing the command, you receive an error that the application is not found, wait for some time and ensure from portal that the app registration has access to ADX and try again.

    User's image

    In addition, kindly refer to this document to know more about cluster level permissions and database permissions.

    1. Manage Azure Data Explorer cluster permissions
    2. Manage Azure Data Explorer database permissions

    Hope this info helps.

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

0 additional answers

Sort by: Most helpful