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

Valeria Naldi 105 Reputation points
2023-04-27T01:19:28.1233333+00:00
I would like to create a web application where to run ADX queries
I followed instruction here to create and register the AAD application: 
https://learn.microsoft.com/en-us/azure/data-explorer/provision-azure-ad-app

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.
547 questions
{count} votes

Accepted answer
  1. KranthiPakala-MSFT 46,602 Reputation points Microsoft Employee
    2023-04-28T23:59:00.7433333+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.