azure - 如何在 node.js 中使用 "@azure/ms-rest-nodeauth"获取 Azure 凭据?

标签 azure azure-functions azure-web-app-service

const msRestNodeAuth = require("@azure/ms-rest-nodeauth");

module.exports = async function (context, req) {   
    let credentials = await msRestNodeAuth.loginWithServicePrincipalSecret(clientId, clientSecret, tenant);
    console.log('credentials==> ',credentials);

    context.res = {
        body: credentials
    };
}

生成凭据时出现错误。 “发生异常:错误:在缓存中找不到条目。”。

为什么我会收到上述错误?

最佳答案

您可以先引用官方文档。

<强> Manage Azure websites with Node.js

我已经测试过了,它对我有用。我使用 npm i @azure/ms-rest-nodeauthnpm i azure-arm-resource 来运行我的测试代码。

const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
const resourceManagement = require("azure-arm-resource");

var clientId = "3b417***f7928ad";;
var domain = "72f9****1db47";
var secret = "RnX****7X1T";
var subscriptionId = 'b83***4c23f';
var resourceClient;

msRestNodeAuth.loginWithServicePrincipalSecret(clientId, secret, domain, function (err, credentials) {
  if (err) return console.log(err);
  resourceClient =new resourceManagement.ResourceManagementClient(credentials, subscriptionId);
  console.log('apiVersion==> ',resourceClient.apiVersion);
})

enter image description here

关于azure - 如何在 node.js 中使用 "@azure/ms-rest-nodeauth"获取 Azure 凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65231325/

相关文章:

azure - 使用 VS 2019 将 .NET Core 3.1 Web 应用程序发布到 Azure 应用服务 Linux,并显示欢迎屏幕

azure - 无法获取访问 token 。 'AADSTS500011: The resource principal named ' xxx' 未在租户-tenantid 中找到

java - Java 中的 Azure Function 无法在本地运行

具有 IoT 中心触发器的 Java Azure 函数未启动

azure - Azure 搜索上的 CORS 问题

azure - 如何使用 Azure CLI 或 Terraform 创建 DNS A 记录

java - 如何使用 Spark 和 Java 来使用来自 Azure eventhub 的数据

Azure 应用服务移动身份验证与 MVC/Forms 不兼容

azure - 有没有办法在 Azure 应用服务中记录 http 请求的正文?

Azure 应用服务 - Google 帐户 ID 不匹配