I've created a new GitHub App and I'm trying to authenticate from Node. I'm new to GitHub Apps, for example, I don't know what "installationId" is supposed to be. Is that the App ID?
I successfully get a token using a private key, but when I try using the API, I get an error both from Node and from curl.
import { createAppAuth } from '@octokit/auth-app';
import { request } from '@octokit/request';
const privateKey = fs.readFileSync(__dirname + 'file.pem');
const auth = createAppAuth({
id: 1,
privateKey,
installationId: 12345,
clientId: 'xxx.xxxxxx',
clientSecret: 'xxxxxx',
});
const appAuthentication = await auth({ type: 'app' });
console.log(`Git repo token: ` + appAuthentication.token);
const result = await request('GET /orgs/:org/repos', {
headers: {
authorization: 'token ' + appAuthentication.token,
},
org: 'orgname',
type: 'public',
});
return res.status(200).json({ message: 'Git result: ' + result });
Here is the curl example I tried after getting the token from the Node code above.
curl -i -X POST -H "Authorization: Bearer xxxxxxxxxx" -H "Accept: application/vnd.github.machine-man-preview+json" https://api.github.com/app
The result in Node: "Git result: Git repo error: HttpError: Bad credentials"
Result in curl: { "message": "Integration not found", "documentation_url": "https://developer.github.com/v3" }
'token '
. I believe you may have to use'Bearer '
instead – Jariah