4

I've uploaded an SSL certificate to my Azure Web App, running on Node, and now I'd like to access my certificate programmatically from my Node scripts to use it for signing JWTs. Is there a way to do this?

I've found similar answers for C#, but I haven't been able to translate this into Node-world.

Update

Here is code that worked successfully, with help from @peter-pan-msft. Before running this code, I had to SFTP upload my SSL certificate to a private folder on the server.

process.env.KEY = fs.readFileSync('path-to-private-folder/mykey.pem');

const jwt = require('jsonwebtoken');

const token = jwt.sign(payload, process.env.KEY, opts);
Community
  • 1
  • 1
dwhieb
  • 1,706
  • 19
  • 29

1 Answers1

3

There are two samples separately from AzureAD on GitHub and azure-mgmt on npmjs.org.

  1. https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/master/sample/certificate-credentials-sample.js
  2. https://www.npmjs.com/package/azure-mgmt

If you want to use the certification for doing Azure Management, you can directly refer to the second sample.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • 1
    Thanks very much for the links. It seems that in both of them, the certificate is retrieved by using Node's fs module to read the .pem file. When I uploaded my SSL certificate to my Web App in the Azure portal, did it automatically save the certificate to the filesystem somewhere that would allow me to access it with the fs module, or do I still need to SFTP upload the certificate somewhere? – dwhieb Feb 29 '16 at 06:46
  • 1
    @dwhieb As I known, you still need to upload the certificate to the website path that be accessed by your code. – Peter Pan Feb 29 '16 at 06:50