Я пытаюсь загрузить внешний файл .pem для подписи с помощью JWT в node.js, но jwt.sign ничего не возвращает. Похоже, что файл .pem загружается неправильно.
Надеемся, что кто-то может помочь.
Вот код:
function(properties, context) {
const jwt = require('jsonwebtoken');
const https = require('https');
https.get(properties.privateKeyName, res => {
// Initialise an array
const bufs = [];
// Add the data to the buffer collection
res.on('data', function (chunk) {
bufs.push(chunk)
});
// This signifies the end of a request
res.on('end', function () {
// We can join all of the 'chunks' of the file together
const privateKey = Buffer.concat(bufs);
const issuer = properties.issuer;
const client_id = properties.client_id;
const aud = 'https://revolut.com'; // Constant
const payload = {
"iss": issuer,
"sub": client_id,
"aud": aud
};
const token = jwt.sign(payload, privateKey, { algorithm: 'RS256', expiresIn: 60 * 60});
return {
'jwt_token': token,
'jwt_test': 'test',
}
});
})
}