我正在尝试按照此处的说明将JWT标识为api.github.com上的应用程序:
https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/
我不知道自己在做什么错,但是我总是会收到“不良凭证”。 有人可以在这里查看我的代码并弄清楚吗? (Node JS)
var fs = require('fs');
var jwt = require('jsonwebtoken');
var privateKey = fs.readFileSync('doronsaartestapp.pem');
var token = jwt.sign(
{
iat: new Date().getTime() / 1000,
exp: new Date().getTime() / 1000 + 10*60,
iss: 'Iv1.5a751653c88a7cd2'//84487
},
privateKey,
{algorithm: 'RS256'}
);
console.log('token: ' + token);
var http = require('https');
var options = {
host: 'api.github.com',
path: '/repos/doronsaar/panther-proxy/hooks',
headers: {
'Accept': 'application/vnd.github.v3.raw+json',
'Authorization': 'Bearer ' + token,
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
}
};
callback = function(response) {
console.log("response status code: " + response.statusCode);
var str = '';
//another chunk of data has been received, so append it to `str`
response.on('data', function (chunk) {
console.log(chunk.toString());
});
//the whole response has been received, so we just print it out here
response.on('end', function () {
console.log("--end--");
});
}
http.request(options, callback).end();