使用Azure Management API进行身份验证时出现403错误 - nodejs

时间:2015-09-18 20:51:27

标签: node.js azure ssl ssl-certificate

我正在使用以下npm尝试使用NodeJS创建云服务。 https://www.npmjs.com/package/azure-mgmt-compute

这是我正在使用的代码:

    var file = __dirname + '/azure-cert.pem';

    var computeManagementClient = computeManagement.createComputeManagementClient(computeManagement.createCertificateCloudCredentials({
        subscriptionId: userCredentials.subscriptionId,
        pem: fs.readFileSync(file, 'utf-8')
    }));

我收到错误:“服务器无法验证请求。验证证书是否有效并与此订阅相关联”。 状态代码403。

我已经完成了这里所写的内容: https://msdn.microsoft.com/en-us/library/azure/gg551722.aspx

使用OpenSSL转换为PEM。

我也尝试了以下内容:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout azure-cert.pem -out azure-cert.pem

pkcs12 -export -out azure-cert.pfx -in azure-cert.pem -name“My Self Signed Cert”

openssl x509 -outform der -in azure-cert.pem -out azure-cert.cer

一切都失败了。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我尝试按照"如何使用 - >部分进行操作。身份验证"页面https://www.npmjs.com/package/azure-mgmt-compute通过Azure Xplat-CLI获取.pem文件并运行示例代码。它工作正常。

首先,您需要通过命令npm install -g azure-cli安装Azure Xplat-CLI,请参阅https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/

您需要通过命令azure login -u <username>连接到Azure订阅,请参阅https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-connect/

然后您可以命令azure account cert export获取.pem文件。该代码适用于订阅ID&amp; pem文件。

最诚挚的问候!

相关问题