Title: 401 - A JSON web token could not be decoded when following App example · Issue #19 · github-developer/github-app-template · GitHub
Open Graph Title: 401 - A JSON web token could not be decoded when following App example · Issue #19 · github-developer/github-app-template
X Title: 401 - A JSON web token could not be decoded when following App example · Issue #19 · github-developer/github-app-template
Description: Expected Behavior I am following the example of using GitHub API's in a GitHub app. This page links to another page showing how to setup the development environment to do this. I followed the instructions on that page, with one differenc...
Open Graph Description: Expected Behavior I am following the example of using GitHub API's in a GitHub app. This page links to another page showing how to setup the development environment to do this. I followed the instr...
X Description: Expected Behavior I am following the example of using GitHub API's in a GitHub app. This page links to another page showing how to setup the development environment to do this. I followed the i...
Opengraph URL: https://github.com/github-developer/github-app-template/issues/19
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"401 - A JSON web token could not be decoded when following App example","articleBody":"## Expected Behavior\r\n\r\nI am following the [example](https://docs.github.com/en/developers/apps/guides/using-the-github-api-in-your-app) of using GitHub API's in a GitHub app. This page links to [another page](https://docs.github.com/en/developers/apps/getting-started-with-apps/setting-up-your-development-environment-to-create-a-github-app) showing how to setup the development environment to do this. \r\nI followed the instructions on that page, with one difference, for testing, I kept the contents of the pem file in the code 64-encoded. The code then proceeds to decode that string to get the actual content of the pem file, and use that to construct the `PRIVATE_KEY`. So, it looks like this\r\n\r\n```\r\n PRIVATE_KEY_ENCODED = \"some long string\"\r\n PRIVATE_KEY_DECODED = (Base64.decode64(PRIVATE_KEY_ENCODED)).gsub('\\n', \"\\n\")\r\n PRIVATE_KEY = OpenSSL::PKey::RSA.new(PRIVATE_KEY_DECODED)\r\n```\r\n\r\n## Actual Behavior\r\n\r\nWhen I install the GitHub app in a new organization, I the following error:\r\n`POST https://api.github.com/app/installations/27776345/access_tokens: 401 - A JSON web token could not be decoded // See: https://docs.github.com/rest (Octokit::Unauthorized)`.\r\n\r\nThis error occurs when the code tries to [get the token of a specific installation](https://github.com/github-developer/github-app-template/blob/master/template_server.rb#L117)\r\n`@installation_token = @app_client.create_app_installation_access_token(@installation_id)[:token]`\r\n\r\n## Steps to Reproduce\r\n\r\nFollow instructions in https://docs.github.com/en/developers/apps/getting-started-with-apps/setting-up-your-development-environment-to-create-a-github-app.\r\n\r\n## Context\r\n\r\nIn testing the code, in a Ruby console, I debugged the ran the template_server.rb file and placed a `binding.pry` right before [the error is thrown](https://github.com/github-developer/github-app-template/blob/master/template_server.rb#L117).\r\nI did the following:\r\n\r\n```\r\n# This is taken from https://github.com/github-developer/github-app-template/blob/master/template_server.rb#L94\r\n\r\npayload = {\r\n # The time that this JWT was issued, _i.e._ now.\r\n iat: Time.now.to_i,\r\n\r\n # JWT expiration time (10 minute maximum)\r\n exp: Time.now.to_i + (10 * 60),\r\n\r\n # Your GitHub App's identifier number\r\n iss: APP_IDENTIFIER\r\n }\r\n\r\n# Calculate a jwt\r\njwt = JWT.encode(payload, PRIVATE_KEY, 'RS256')\r\n\r\n# display the installation id\r\n@installation_id\r\n```\r\n\r\nThen I ran the following cURL command in a command line.\r\n\r\ncurl -i -X POST \\\r\n-H \"Authorization: Bearer \u003cjwt\u003e\" \\\r\n-H \"Accept: application/vnd.github+json\" \\\r\nhttps://api.github.com/app/installations/\u003c@installation_id\u003e/access_tokens\r\n\r\nI received a valid response that did include a token. So, it doesn't seem that the problem is in the code itself, but that for some reason the `Octokit::Client` is not doing the right thing in calling the intended API.\r\n\r\n","author":{"url":"https://github.com/hanysf","@type":"Person","name":"hanysf"},"datePublished":"2022-07-28T21:13:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/19/github-app-template/issues/19"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:06deef73-61f1-f1ce-ea85-83f9067a385a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E598:32A919:6F5E5:9760E:69826BC0 |
| html-safe-nonce | 392528b0f772f5a1674f3f897a1b63de8c91043fbdc5d1ea1cdfd2f4fa9a1984 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTk4OjMyQTkxOTo2RjVFNTo5NzYwRTo2OTgyNkJDMCIsInZpc2l0b3JfaWQiOiI3MDYwOTY0NzA2NDE2MjI1MjE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8e01c22281cc406798dab4b950f9526eb6fddad360e92de8ad62f9f1c9dbb02e |
| hovercard-subject-tag | issue:1321494853 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github-developer/github-app-template/19/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c1a0383be3cad7c3ebad927c6c9762c93a3cf4c2401e6dbacc6039670281be37/github-developer/github-app-template/issues/19 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c1a0383be3cad7c3ebad927c6c9762c93a3cf4c2401e6dbacc6039670281be37/github-developer/github-app-template/issues/19 |
| og:image:alt | Expected Behavior I am following the example of using GitHub API's in a GitHub app. This page links to another page showing how to setup the development environment to do this. I followed the instr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hanysf |
| hostname | github.com |
| expected-hostname | github.com |
| None | d8cbbf00e6212b4e561a1d6db613194a319d58a2967494f7cc81cf6da3fbb985 |
| turbo-cache-control | no-preview |
| go-import | github.com/github-developer/github-app-template git https://github.com/github-developer/github-app-template.git |
| octolytics-dimension-user_id | 13240041 |
| octolytics-dimension-user_login | github-developer |
| octolytics-dimension-repository_id | 157603879 |
| octolytics-dimension-repository_nwo | github-developer/github-app-template |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 157603879 |
| octolytics-dimension-repository_network_root_nwo | github-developer/github-app-template |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 15d777483e72943a892af4ab5c0bbdb20215e6f3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width