首页 > 解决方案 > 使用现有 AAD 令牌为 Kusto 请求令牌

问题描述

我正在尝试让用户登录到我的机器人(Microsoft 机器人框架)并进行 Kusto 查询。我已成功获得 Graph JWT,但我不知道如何请求 Kusto 访问权限。

AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-*********");
            var clientAppID = "974c5166-f8b5-466e-9552-*********";
            var secret = "[*SxczFa7qU*******************";
            var tokenForKusto = await authContext.AcquireTokenAsync(
               "https://aznw.kusto.windows.net",
               new ClientCredential(clientAppID, secret),
               new UserAssertion(userToken));

我希望tokenForKusto是一个有效的令牌,但它会引发异常。 {"AADSTS500131: Assertion audience does not match the Client app presenting the assertion. The audience in the assertion was '00000002-0000-0000-c000-000000000000' and the expected audience is '974c5166-f8b5-466e-9552-********' or one of the Application Uris of this application with App ID '974c5166-f8b5-466e-9552-********'(testbotbuilderAAD).\r\nTrace ID: 38515779-b858-4efc-8b03-e9f8ec810c00\r\nCorrelation ID: a136600d-66e0-44fc-8f24-d1fda6b4ba56\r\nTimestamp: 2019-07-19 17:23:27Z"}

标签: oauthazure-active-directoryazure-data-explorer

解决方案


这是因为您尝试使用为 Graph 颁发的令牌,但您的应用程序不是 Graph。仅当且仅当客户端应用程序 ID(来自 ClientCredentials)与您尝试使用的令牌的受众匹配时,此流程才有效。

无论如何,您为什么要检索 Graph 的令牌?如果要发出 Kusto 查询,则应使用集群 URI 作为资源(例如,“ https://cluster.region.kusto.windows.net ”)


推荐阅读