无法使用应用令牌对api.github.com进行身份验证

时间:2020-10-15 06:58:41

标签: jwt token github-api

我正在尝试按照此处的说明将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();

0 个答案:

没有答案