我在 Node.js 上运行 Azure Functions。 (另请注意,通过应用服务计划的底层操作系统是 Windows)
我先绕一点路吧
我一直在通过 Node.js 代码访问 Azure Key Vault,所以我知道如何从 Node.js 代码访问 Key Vault,所以它看起来像这样:
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const AzureCredential = new DefaultAzureCredential();
const kvEndpoint = "Key Vault Endpoint Url";
const kvClient = new SecretClient(kvEndpoint, AzureCredential);
const API_KEY = (await kvClient.getSecret("Key Name")).value;
但这只是 Azure Key Vault,这不是我正在寻找的东西。我分享上述代码的原因是为了强调,从 Node.js 连接到 Azure Key Vault 也非常简单。为此,Node.js 包已完成。
现在。我想读取直接上传到 Azure Function App 仪表板本身的证书边栏选项卡的“公钥”(.cer)。 (不是 Key Vault 中的那个)。上传后是这样的:
,但他们提到的所有文档仅适用于 C# 和 Java。 非常感谢所有帮助。
中获取代码来获取 Azure function App=>Certificates=>Public Key Certificates(.cer)
下可用的证书:
添加应用程序设置
WEBSITE_LOAD_CERTIFICATES
*
作为其在 Function App=>Environment Variables
中的值:
代码片段:
const http = require('http');
const ca = require('win-ca');
// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
// Set a response type of plain text for the response
res.writeHead(200, { 'Content-Type': 'text/plain' });
// fetching certificates
let certificates = []
ca({
format:ca.der2.pem,
store: ['My'],
ondata: crt => certificates.push(crt)
})
res.end("Certificate count under 'My' store is" + certificates);
});
let port = process.env.PORT || 3000;
app.listen(port);
console.log('Node server running on port ' + port);