create-github-app-token: `A JSON web token could not be decoded` error when running action
Hi, I get this error when running the action:
Run actions/create-github-app-token@v1
with:
app-id: ***
private-key: ***
github-api-url: https://api.github.com/
owner and repositories not set, creating token for the current repository ("fusion-imu")
Failed to create token for "fusion-imu" (attempt 1): A JSON web token could not be decoded - https://docs.github.com/rest
Failed to create token for "fusion-imu" (attempt 2): A JSON web token could not be decoded - https://docs.github.com/rest
Failed to create token for "fusion-imu" (attempt 3): A JSON web token could not be decoded - https://docs.github.com/rest
Failed to create token for "fusion-imu" (attempt 4): A JSON web token could not be decoded - https://docs.github.com/rest
RequestError [HttpError]: A JSON web token could not be decoded - https://docs.github.com/rest
at /home/runner/work/_actions/actions/create-github-app-token/v1/dist/main.cjs:37050:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async hook4 (/home/runner/work/_actions/actions/create-github-app-token/v1/dist/main.cjs:39454:18)
at async getTokenFromRepository (/home/runner/work/_actions/actions/create-github-app-token/v1/dist/main.cjs:39768:20)
at async RetryOperation._fn (/home/runner/work/_actions/actions/create-github-app-token/v1/dist/main.cjs:39645:24) {
status: 401,
request: {
method: 'GET',
url: 'https://api.github.com/repos/avsaase/fusion-imu/installation',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'actions/create-github-app-token',
authorization: 'bearer [REDACTED]'
},
request: { hook: [Function: bound hook4] AsyncFunction }
Error: A JSON web token could not be decoded - https://docs.github.com/rest
},
response: {
url: 'https://api.github.com/repos/avsaase/fusion-imu/installation',
status: 401,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
'content-length': '117',
'content-security-policy': "default-src 'none'",
'content-type': 'application/json; charset=utf-8',
date: 'Wed, 03 Jul 2024 22:33:58 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'github.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-media-type': 'github.v3; format=json',
'x-github-request-id': 'E906:311D5D:2A7971:4ADA68:6685D1D2',
'x-xss-protection': '0'
},
data: {
message: 'A JSON web token could not be decoded',
documentation_url: 'https://docs.github.com/rest',
status: '401'
}
},
attemptNumber: 4,
retriesLeft: 0
}
In my workflow file I have
- name: Generate GitHub token
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
The corresponding app id and private key are set as secrets in my repository. The private key is copy-pasted directly from the .pem file that downloads when creating a private key.
The app is installed
Did I do something wrong or is this a bug? Thanks.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 24 (5 by maintainers)
I solved my issue by:
This resulted in a key using the specified format:
Then I copied everything, including the
-----BEGIN PRIVATE KEY-----and-----END PRIVATE KEY-----parts, and pasted on my secret that is used by Github actions.This step above is important (to copy the entire key), if you copy just what is in between it will fail!
This solved my issue.
Found this issue because we’re having the same problem.
Here is an invalidated key that isn’t working when set as a Github Actions secret and fed to this action, including the trailing newline.
Converting it to PKCS#8 with OpenSSL did not work.
I think we’ve figured out what’s going on here!
We were able to reproduce this error by providing a valid app ID and a private key that do not match. Please double-check that you are using the correct app ID and a valid private key that belongs to that app.
We’d like to make the error more helpful for those that encounter this error in the future. Pull requests welcome! See https://github.com/octokit/auth-app.js/issues/375 for more information.
Can you please try to convert PKCS#1 (the current format that GitHub exports) to PKCS#8 and see if that helps? I documented 3 options to do that here: https://github.com/gr2m/universal-github-app-jwt/?tab=readme-ov-file#converting-pkcs1-to-pkcs8
The PKCS8 key start with
-----BEGIN PRIVATE KEY-----. Make sure to leave that line as well as the ending line in when setting it as a repository secretClarifying my last response now. Using the OpenSSL method of converting the key, it is now being accepted by this action.
However, this feels like a bit of a poor user experience to issue the key(s) one way but have your own vendor provided action expect them in a different format.
I encountered a similar issue and resolved it by running this command:
cat my-app.private-key.pem | awk 'BEGIN {ORS="\\n"} {print}' | head -c -2 > my-app.private-key-escaped.pemThis reformatted the private key correctly. I hope this helps!
I came here to say I ran into this myself, where I had accidentally set the “installation ID” as the “app ID”, and amending that fixed it. 🙈