Ich versuche, ein Zugriffstoken von Github mit einem NodeJS-Client zu erhalten.Getting-Access-Token von Github
const axios = require("axios");
var jwt = require("jsonwebtoken");
exports.openedPOST = function openedPOST(req, res) {
// generate jwt
const now = Math.round(Date.now()/1000);
const payload = {
// issued at time
iat: now,
// expires in 10min
exp: now + 600,
// Github app id
iss: 6700
};
const token = jwt.sign(payload, cert, { algorithm: "RS256" });
console.log(token)
// auth to github
axios({
method: "get",
url: "https://api.github.com/app",
headers: {
Accept: "application/vnd.github.machine-man-preview+json",
Authorization: `Bearer ${token}`
}
})
.then(function(response) {
console.log(response.data);
})
.catch(function(error) {
console.warn("Unable to authenticate");
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
if (error.response) {
console.warn(`Status ${error.response.status}`);
console.warn(`${error.response.data.message}`);
}
});
res.status(200).end();
Aber das erzeugt nur: { "message": "A JSON web token could not be decoded", "documentation_url": "https://developer.github.com/v3" }
ich das Token bei https://jwt.io prüft haben, und die Nutzlast ist wie erwartet.
hast du das jemals gelöst? – pac
Nein. Keine Ahnung, warum es scheitert. – timbo
Es mag keinen Unterschied machen, aber ich habe das manuell gemacht, indem ich ein Ruby-Skript benutzt habe, um das Token zu generieren. Ich habe festgestellt, dass "iss: 6700" zu der Nachricht führen würde, die Sie erhalten haben, aber "" iss: 6700 "" hat die Tokengenerierung erlaubt zu arbeiten. Entschuldigung, wenn ich aus dem Thema bekomme, aber wie haben Sie 'cert' generiert? – pac