Communicating with the Github App API?

Has anyone used Netlify Functions to communicate with the GitHub API as a GitHub App? GitHub App authentication requires generating a JWT based on a client ID & PEM private key. In my Netlify Function, both of these are successfully brought in from the Netlify UI build environment variables (I can successfully log them both). However, anytime I pass them to Github to create a JWT, I receive: error:0906D06C:PEM routines:PEM_read_bio:no start line
Here’s an example of how I’m attempting to authenticate:

const { App } = require("@octokit/app");

const APP_ID = process.env.GITHUB_APP_ID;
const PRIVATE_KEY = process.env.GITHUB_PRIVATE_KEY;

const app = new App({ id: APP_ID, privateKey: PRIVATE_KEY });
const jwt = app.getSignedJsonWebToken();

The error occurs at getSignedJsonWebToken. I’ve also tried a different auth technique using @octokit/auth-app but ran into the same error. Anyone have experience doing this?

Hi Karl,

I doubt your assertion that there are any functional authentication tokens in the build environment unless they are ones that YOU setup. Ours are only usable before build, not even during build.

You’ll want to implement whatever auth you need on your own, rather than trying to piggyback on ours which is only intended to be used by the process that clones your repo and the one that sends notifications (e.g. a comment on a PR) - not by your own code.

Sorry if I miscommunicated here; Yes, all of these were set up by me. I entered my own Github App Id and Private Key in the Netlify UI in the “deploy settings > environment” section, so I referred to them as that to distinguish from some other environment variable like something in a .env file. Wasn’t trying to pull something of Netlify’s and I doubt that’s even possible.
I was just trying to make the pem I entered work, and was asking if anyone had experience solving this error. Thought I might have to format it differently for that deploy settings field. Sorry for the confusion.

Ah, thanks for that clarification! I don’t know that I’ve seen anyone do that, and it does make sense now :).

Does it work when you try to use netlify-lambda serve with it locally? That’ll almost certainly treat you better as you troubleshoot than trying to debug from our function logs…