Загрузите внешний файл с помощью node.js и используйте с jwt.sign - PullRequest
0 голосов
/ 28 октября 2019

Я пытаюсь загрузить внешний файл .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',
                }


            });
        })

}

1 Ответ

0 голосов
/ 28 октября 2019

Я считаю, что для секретного ключа алгоритм не RS256. Это RSA или ECDSA.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...