rest - 使用 AAD 在 Application Insights REST API 上进行身份验证

标签 rest api authentication azure-application-insights

到目前为止,我成功使用 Application Insights REST API 来获取带有 X-Api-Key header 的指标。 https://api.applicationinsights.io/beta/apps/xxxxxxxxxx/metrics/customMetrics%2FmetricName?timespan=PT2H&interval=PT20M&aggregation=min

但是,通过我们的新仪表板抓取多个指标,我们严重达到了 1500 个请求/API key 限制。

有些人建议尝试使用多个 api key ,但我想阻止这种方法。

根据文档,使用 AAD 进行身份验证将删除每日上限 ( https://dev.applicationinsights.io/documentation/Authorization/Rate-limits )

但是我无法使用AAD进行身份验证(在nodejs中,但我怀疑它在任何语言中都是相同的)

我在一个简单的应用程序中使用了adal-node,我成功获得了一个 token ,但是我无法将其转发到Request

var context = new AuthenticationContext(authorityUrl);

context.acquireTokenWithClientCredentials(resource, clientId, clientSecret, function(err, tokenResponse) {
  if (err) {
    console.log('well that didn\'t work: ' + err.stack);
  } else {
    console.log(tokenResponse);

    request({'url' : 'https://api.applicationinsights.io/beta/apps/xxxxxxxxx/metrics/customMetrics%2Fmetrics?timespan=PT2H&interval=PT20M&aggregation=min',
    headers: {
            'Authorization': 'Bearer ' + tokenResponse.accessToken
        }
    }, function (error,response,body){
            console.log(body);
    });
  }
});

enter image description here

我收到以下错误消息 提供的身份验证对此资源无效 给定的 API key 对于请求的资源无效

我怀疑我错过了什么:)

最佳答案

我们的 REST API 不直接支持 AAD。您的资源由 Azure 资源管理器管理,并且只有它才能验证特定用户是否有权访问该资源。 API key 是我们直接将授权短路到资源的方法,而不是在用户上下文中。

您以您自己的身份授予此 AAD 应用对此资源的访问权限,因此身份验证仍在用户上下文中进行。必须改为调用 ARM:' https://management.azure.com/subscriptions/xxxxxx/resourcegroups/xxxxx/providers/microsoft.insights/components/xxxxx/api/metrics/customMetrics%2Fmetrics?api-version=2014-12-01-preview&timespan=PT2H&interval=PT20M&aggregation=min '

文档链接至此处 - 尽管未明确解释:https://dev.applicationinsights.io/documentation/Authorization

这将为您带来更高的速率限制,并且仍然返回与 REST API 相同的响应。

关于rest - 使用 AAD 在 Application Insights REST API 上进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978366/

相关文章:

database - 跟踪网页内容在一个页面中被浏览的次数?

windows - 我是如何在我的应用程序中获得这个隐藏的 "URL Moniker Notification Window"的?

python - Django 抽象用户模型未迁移

c# - ASP.NET Core,在用户登录时收到通知

android - Google Fit Android API 中的手动数据标志?

java - 如何生成随机字母数字字符串并将其插入同一( Activity )页面上的组的登录/注册框

rest - HereMaps - 这些凭据不授权访问。无法获得公共(public)交通 API 的有效响应

java - 在为 mapstruct 制作的抽象类中 Autowiring

web-services - 使用 HTTP 状态代码时区分基础结构和业务逻辑

javascript - 如何从使用 instagram API 的地方获取 instagram 图片?