1
votes

I'm using the following npm to try and create a cloud service using NodeJS. https://www.npmjs.com/package/azure-mgmt-compute

This is the code i'm using:

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

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

I'm getting the error: "The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription". Status code 403.

I've done what's written here: https://msdn.microsoft.com/en-us/library/azure/gg551722.aspx

And converted to PEM using OpenSSL.

I also tried the following:

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

Everything fails. Any ideas?

1

1 Answers

1
votes

I tried to follow the section "How to Use -> Authentication " of the page https://www.npmjs.com/package/azure-mgmt-compute to get the .pem file via Azure Xplat-CLI and run the sample code. It works fine.

Firstly you need to install the Azure Xplat-CLI via command npm install -g azure-cli, please refer to https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/.

Secordly you need to connect to your Azure subscription via command azure login -u <username>, please refer to https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-connect/.

Then you can command azure account cert export to get the .pem file. The code works with the subscription id & pem file.

Best Regards!