首页 > 解决方案 > Azure 资源管理器身份验证失败

问题描述

我正在尝试使用 node.js 通过以下示例代码访问 azure 资源管理器:

msRestAzure.interactiveLogin(function(err, credentials) {
	if (err) console.log(err);
 var client = new resourceManagement.ResourceManagementClient(credentials, 'token');
 client.resources.list(function(err, result) {
   if (err) console.log(err);
   console.log(result);
 });
});

运行时出现以下错误:

 { Error: The access token is from the wrong issuer 'https://sts.windows.net/token/'. It must match the tenant 'https://sts.windows.net/token/' associated with this subscription. Please use the authority (URL) 'https://login.windows.net/token' to get the token. Note, if the subscription is transferred to another tenant there is no impact to the services, but information about new tenant could take time to propagate (up to an hour). If you just transferred your subscription and see this error message, please try back later.
    at client.pipeline.error (D:\azure-arm\node_modules\azure-arm-resource\lib\resource\operations\resources.js:496:19)
    at retryCallback (D:\azure-arm\node_modules\ms-rest\lib\filters\systemErrorRetryPolicyFilter.js:89:9)
    at retryCallback (D:\azure-arm\node_modules\ms-rest\lib\filters\exponentialRetryPolicyFilter.js:140:9)
    at D:\azure-arm\node_modules\ms-rest\lib\filters\rpRegistrationFilter.js:59:14
    at handleRedirect (D:\azure-arm\node_modules\ms-rest\lib\filters\redirectFilter.js:39:9)
    at D:\azure-arm\node_modules\ms-rest\lib\filters\formDataFilter.js:23:14
    at Request.defaultRequest [as _callback] (D:\azure-arm\node_modules\ms-rest\lib\requestPipeline.js:125:16)
    at Request.self.callback (D:\azure-arm\node_modules\request\request.js:185:22)
    at emitTwo (events.js:106:13)


    at Request.emit (events.js:191:7)

任何你看到令牌的地方,我都替换了那里的实际值。我提供的订阅 ID 是正确的。我试过直接登录而不是使用上面的密钥,它具有相同的效果。理想情况下,我们希望 azure 中的应用程序能够访问 arm API,但在活动目录中似乎不可能,而且我似乎无法让它工作。任何帮助,将不胜感激。

标签: node.jsazureazure-resource-manager

解决方案


我使用了 ms-rest-azure 版本 2.6.0 和 azure-arm-resource 版本 7.3.0,并且使用相同的代码对我来说工作正常。

我认为使用服务主体身份验证方式或基本身份验证方式而不是交互式登录身份验证方式进行身份验证是安全的。我们在这里有这些其他身份验证方式的步骤-> https://github.com/Azure/azure-sdk-for-node/blob/master/Documentation/Authentication.md#using-authentication-in-your- nodejs-script如果有兴趣,您可以尝试。

此外,由于您理想地在 Azure 中寻找可以访问 ARM API 的应用程序,所以我认为值得阅读这篇文章 -> https://docs.microsoft.com/en-us/azure/azure-资源管理器/资源管理器 API 身份验证

希望这可以帮助!!


推荐阅读