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

本文涉及的产品
应用实时监控服务-用户体验监控,每月100OCU免费额度
Serverless 应用引擎免费试用套餐包,4320000 CU,有效期3个月
可观测可视化 Grafana 版,10个用户账号 1个月
简介: 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",
  });

 



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

相关文章
|
1月前
|
Java 开发工具 Windows
【Azure App Service】在App Service中调用Stroage SDK上传文件时遇见 System.OutOfMemoryException
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
|
3月前
|
Kubernetes API 开发工具
【Azure Developer】通过SDK(for python)获取Azure服务生命周期信息
需要通过Python SDK获取Azure服务的一些通知信息,如:K8S版本需要更新到指定的版本,Azure服务的维护通知,服务处于不健康状态时的通知,及相关的操作建议等内容。
52 18
|
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月前
|
消息中间件 开发工具
【Azure Service Bus】Service Bus SDK 抛出 ERROR c.a.c.a.i.ActiveClientTokenManager - Error is transient. Rescheduling authorization task at interval 1079000 ms.
【Azure Service Bus】Service Bus SDK 抛出 ERROR c.a.c.a.i.ActiveClientTokenManager - Error is transient. Rescheduling authorization task at interval 1079000 ms.
|
4月前
|
JavaScript 前端开发 Java
[Android][Framework]系统jar包,sdk的制作及引用
[Android][Framework]系统jar包,sdk的制作及引用
114 0
|
1月前
|
Java Linux API
Android SDK
【10月更文挑战第21天】
78 1
|
2月前
|
程序员 开发工具 Android开发
Android|使用阿里云推流 SDK 实现双路推流不同画面
本文记录了一种使用没有原生支持多路推流的阿里云推流 Android SDK,实现同时推送两路不同画面的流的方法。
67 7
|
4月前
|
开发工具 Android开发
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
190 4
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
|
4月前
|
Dart 开发工具 Android开发
Android Studio导入Flutter项目提示Dart SDK is not configured
Android Studio导入Flutter项目提示Dart SDK is not configured
392 4
下一篇
DataWorks