【Azure Developer】使用JavaScript通过SDK进行monitor-query的client认证报错问题

本文涉及的产品
性能测试 PTS,5000VUM额度
应用实时监控服务-应用监控,每月50GB免费额度
Serverless 应用引擎免费试用套餐包,4320000 CU,有效期3个月
简介: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant.

问题描述

使用JavaScript通过SDK进行monitor-query的client初始化时候,需要进行认证时报错AADSTS90002。

代码如下:

const credential = new DefaultAzureCredential();
const logsQueryClient = new LogsQueryClient(credential , {
    endpoint: "https://api.loganalytics.azure.cn/v1"   
    ,audience: "https://api.loganalytics.azure.cn/.default",
  });

截图如下:

报错如下:

2024-06-26 16:26:05 [error] AuthenticationError: EnvironmentCredential authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.

Status code: 400More details:invalid_request: 90002 -

[2024-06-26 08:26:05Z]: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant.

Trace ID: xxxxxxxx-hgef-dre9-xxxx-xxxxxxxxxxxx

Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Timestamp: 2024-06-26 08:26:05Z -

Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -

Trace ID: xxxxxxxx-hgef-dre9-xxxx-xxxxxxxxxxxx

at (/code/node_modules/@azure/identity/dist/index.js:3673:49) at processTicksAndRejections (node:internal/process/task_queues:96:5)

at withSpan (/code/node_modules/@azure/core-tracing/dist/commonjs/tracingClient.js:36:28)

at (/code/node_modules/@azure/identity/dist/index.js:3340:29)

at withSpan (/code/node_modules/@azure/core-tracing/dist/commonjs/tracingClient.js:36:28)

at getToken (/code/node_modules/@azure/identity/dist/index.js:3330:27)

at tryGetAccessToken (/code/node_modules/@azure/core-rest-pipeline/dist/commonjs/util/tokenCycler.js:36:32)

at beginRefresh (/code/node_modules/@azure/core-rest-pipeline/dist/commonjs/util/tokenCycler.js:44:17)

at defaultAuthorizeRequest (/code/node_modules/@azure/core-rest-pipeline/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js:21:25)

at sendRequest (/code/node_modules/@azure/core-rest-pipeline/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js:72:13)

{

statusCode: 400,

errorResponse:

{

error: 'EnvironmentCredential authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.',

errorDescription: "invalid_request: 90002 - [2024-06-26 08:26:05Z]: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: xxxxxxxx-hgef-dre9-xxxx-xxxxxxxxxxxx Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Timestamp: 2024-06-26 08:26:05Z - Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - Trace ID: xxxxxxxx-hgef-dre9-xxxx-xxxxxxxxxxxx",

correlationId: undefined,

errorCodes: undefined,

timestamp: undefined,

traceId: undefined

}

}

问题解答

经过对JS SDK源码的分析,最后Azure Monitor团队找到了原因,是需要指定正确的Audience,正确的值为:audience: "https://api.loganalytics.azure.cn"。修改Audience后JS代码可以在中国区正常运行。

 

原代码

const logsQueryClient = new LogsQueryClient(credential , {
    endpoint: "https://api.loganalytics.azure.cn/v1"   
    ,audience: "https://api.loganalytics.azure.cn/.default",
  });

改为:

const logsQueryClient = new LogsQueryClient(credential , {
    endpoint: "https://api.loganalytics.azure.cn/v1"   
    ,audience: "https://api.loganalytics.azure.cn",
  });

 



当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
4月前
|
JavaScript 前端开发 API
【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.(status code 500)
【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.(status code 500)
|
3月前
|
Kubernetes API 开发工具
【Azure Developer】通过SDK(for python)获取Azure服务生命周期信息
需要通过Python SDK获取Azure服务的一些通知信息,如:K8S版本需要更新到指定的版本,Azure服务的维护通知,服务处于不健康状态时的通知,及相关的操作建议等内容。
55 18
|
2月前
|
JavaScript 前端开发
原生js常见报错及其处理方案
原生js常见报错及其处理方案
43 0
|
4月前
|
Java 开发工具
【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到User信息,如Object ID
【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到User信息,如Object ID
|
4月前
|
API 开发工具 网络架构
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
|
4月前
|
开发工具 iOS开发 容器
【Azure Blob】关闭Blob 匿名访问,iOS Objective-C SDK连接Storage Account报错
【Azure Blob】关闭Blob 匿名访问,iOS Objective-C SDK连接Storage Account报错
|
4月前
|
Shell Go 开发工具
【Azure Developer】Go语言调用Azure SDK如何登录到中国区Azure环境
【Azure Developer】Go语言调用Azure SDK如何登录到中国区Azure环境
|
1月前
|
JavaScript 前端开发
JavaScript中的原型 保姆级文章一文搞懂
本文详细解析了JavaScript中的原型概念,从构造函数、原型对象、`__proto__`属性、`constructor`属性到原型链,层层递进地解释了JavaScript如何通过原型实现继承机制。适合初学者深入理解JS面向对象编程的核心原理。
26 1
JavaScript中的原型 保姆级文章一文搞懂
|
5月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的客户关系管理系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的客户关系管理系统附带文章源码部署视频讲解等
105 2
|
1月前
JS+CSS3文章内容背景黑白切换源码
JS+CSS3文章内容背景黑白切换源码是一款基于JS+CSS3制作的简单网页文章文字内容背景颜色黑白切换效果。
20 0