auth-app.js: [BUG]: secretOrPrivateKey must be an asymmetric key when using RS256
What happened?
Generated a privatekey using the GitHub Apps interface, which downloaded a .pem file. I loaded this file directly into my auth config:
auth: {
privateKey: require('fs').readFileSync('./my-key.pem').toString(),
appId: 12345,
installationId: 67890
},
I also tried pasting in the key directly. I also removed all whitespace in a separate attempt. All yielded the same error, which seems to me indicates a problem with the keys being generated from GitHub. Would appreciate any assistance with this.
Relevant error is shown in the log output below.
Versions
"node_modules/@octokit/auth-app": {
"version": "4.0.9",
"node_modules/octokit": {
"version": "2.0.14",
Relevant log output
/home/tim/website/node_modules/jsonwebtoken/sign.js:124
return failure(new Error((`secretOrPrivateKey must be an asymmetric key when using ${header.alg}`)))
^
Error: secretOrPrivateKey must be an asymmetric key when using RS256
at Object.sign (/home/tim/website/node_modules/jsonwebtoken/sign.js:124:22)
at getToken (/home/tim/website/node_modules/universal-github-app-jwt/dist-src/get-token.js:3:25)
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 9
- Comments: 28 (11 by maintainers)
Commits related to this issue
- Update Dockerfile Trying to use Node:19 instead of Node:16 to fix error similar to: ``` https://github.com/octokit/auth-app.js/issues/465 ``` Signed-off-by: Sean P. Goggins <s@goggins.com> — committed to badging/BadgingAPI by sgoggins 5 months ago
- Update Dockerfile Troubleshooting node version as possible source of key error: similar to: ``` https://github.com/octokit/auth-app.js/issues/465 ``` Signed-off-by: Sean P. Goggins <s@goggins.... — committed to badging/BadgingAPI by sgoggins 5 months ago
We fixed this error for us
Getting the same issue in Vercel’s production environment when using serverless functions. The private key works and is authenticated in the dev environment, but I get the “secretOrPrivateKey must be an asymmetric key when using RS256” error when in production.
I tried changing to Node 14, 16, and 18 and get the same error in all of them. Vercel doesn’t have Node 19 as a possible runtime. I also tried regenerating the private key, triple-checked its formatted correctly, and checked my authentication against Octokit docs to make sure it’s structured correctly and I’m still getting the error.
Any updates on why this is happening or a possible fix? Thanks!
Same issue with vercel serverless function using node 18. Has there been any updates on this issue?
I would still like to get to the bottom of why it isn’t working on earlier versions of Node as we still support them.
Thanks, This way it is working.
Node
v20.2.0and getting same error. Does anyone know how to fix it?Oh wow, changing to Node 19 fixes the problem!
For deno support it is recommended to use esm.sh
Out of the box support just isn’t available, yet.
I created https://github.com/gr2m/universal-github-app-jwt/issues/71, happy to accept a pull request for that change. We can leave this open until the change has been implemented. But let’s continue the discussion there
For the next.js env files, you have to replace line breaks with
\nI figured out what is the problem.
The problem is coming from loading environment variables in
nodejs.Working scenario: I put the private key content in
constvariable.All solutions that loads the private key content from environment variable is not worked for me, the problem is environment variable is not loaded with the actual content of the variable:
Printing the
GITHUB_PRIVATE_KEYinto console only gives"-----BEGIN RSA PRIVATE KEY-----part which is the first line.I opened an issue in
nextjsrelated to this problem.Note: Private key is invalidated.
We can probably add this line
if that fixes the problem across all supported Node version. If the fix works, we should probably add it to the lower-level library we use: https://github.com/gr2m/universal-github-app-jwt