Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generating-a-json-web-token-jwt-for-a-github-app.md #34134

Closed
wants to merge 3 commits into from

Conversation

mark-mxwl
Copy link
Contributor

@mark-mxwl mark-mxwl commented Jul 30, 2024

Why:

Closes: #33324
Closes: #33989

What's being changed (if available, include any code snippets, screenshots, or gifs):

Updated formatting for payload JSON to return top-level JSON when decoded, as the previous version was throwing an error for some users. Header JSON moved to single line to match payload. Also removed "JWT: " from print line to avoid scripting conflicts.

Check off the following:

  • I have reviewed my changes in staging, available via the View deployment link in this PR's timeline (this link will be available after opening the PR).

    • For content changes, you will also see an automatically generated comment with links directly to pages you've modified. The comment won't appear if your PR only edits files in the data directory.
  • For content changes, I have completed the self-review checklist.

Updated formatting for payload JSON to return top-level JSON when decoded, as this was throwing an error for some users. Also removed "JWT: " from print line to avoid scripting conflicts.
@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Jul 30, 2024
Copy link
Contributor

github-actions bot commented Jul 30, 2024

Automatically generated comment ℹ️

This comment is automatically generated and will be overwritten every time changes are committed to this branch.

The table contains an overview of files in the content directory that have been changed in this pull request. It's provided to make it easy to review your changes on the staging site. Please note that changes to the data directory will not show up in this table.


Content directory changes

You may find it useful to copy this table into the pull request summary. There you can edit it to share links to important articles or changes and to give a high-level overview of how the changes in your pull request support the overall goals of the pull request.

Source Preview Production What Changed
apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app.md fpt
ghec
ghes@ 3.13 3.12 3.11 3.10
fpt
ghec
ghes@ 3.13 3.12 3.11 3.10

fpt: Free, Pro, Team
ghec: GitHub Enterprise Cloud
ghes: GitHub Enterprise Server

@lindhe
Copy link

lindhe commented Jul 30, 2024

Thanks for fixing this! Great job!

There seem to be some shellcheck warnings left:

$ shellcheck bash.sh

In bash.sh line 5:
pem=$( cat $2 ) # file path of the private key as second argument
           ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
pem=$( cat "$2" ) # file path of the private key as second argument


In bash.sh line 8:
iat=$((${now} - 60)) # Issues 60 seconds in the past
       ^----^ SC2004 (style): $/${} is unnecessary on arithmetic variables.


In bash.sh line 9:
exp=$((${now} + 600)) # Expires 10 minutes in the future
       ^----^ SC2004 (style): $/${} is unnecessary on arithmetic variables.


In bash.sh line 30:
printf '%s\n' $JWT
              ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
printf '%s\n' "$JWT"

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
  https://www.shellcheck.net/wiki/SC2004 -- $/${} is unnecessary on arithmeti...

Maybe let's fix them also.

@nguyenalex836
Copy link
Contributor

@mark-mxwl Thanks so much for opening a PR! I'll get this triaged for review ✨

@nguyenalex836 nguyenalex836 added content This issue or pull request belongs to the Docs Content team waiting for review Issue/PR is waiting for a writer's review github apps Content related to GitHub Apps developers Content related to developers and removed triage Do not begin working on this issue until triaged by the team labels Jul 30, 2024
@mark-mxwl
Copy link
Contributor Author

Thx for the ShellCheck output @lindhe! While those are all valid warnings, we don't really have to worry about globbing (wildcards)/splitting (tab, space, newline) on our positional parameters, due to the type of data we're passing through. The curly braces on the expressions are optional--I kept them there for the sake of consistency and readability.

@brakel
Copy link

brakel commented Jul 31, 2024

Hi, thanks for the update. I ran the updated script, removing the templating, and there still seems to be an issue with the iat claim being a string:

{
  "message": "'Issued at' claim ('iat') must be an Integer representing the time that the assertion was issued",
  "documentation_url": "https://docs.github.com/rest",
  "status": "401"
}

Removing the quotes in the script solves the issue for me.

Interestingly, the same validation is not applied to the exp claim and will work as either a string or int.

Converted `iat` and `exp` values from strings to integers.
@mark-mxwl
Copy link
Contributor Author

Thanks for catching that @brakel. Interesting re: the behavior with exp. I adjusted the script so that iat and exp values are both integers, which hopefully will resolve this.

@Githubant123

This comment was marked as spam.

@Githubant123

This comment was marked as spam.

Githubant123

This comment was marked as spam.

Githubant123

This comment was marked as spam.

Clydonight

This comment was marked as spam.

@nguyenalex836 nguyenalex836 added needs SME This proposal needs review from a subject matter expert waiting for review Issue/PR is waiting for a writer's review and removed waiting for review Issue/PR is waiting for a writer's review labels Aug 23, 2024
Copy link
Contributor

Thanks for opening a pull request! We've triaged this issue for technical review by a subject matter expert 👀

@Jaga416381

This comment was marked as spam.

@nguyenalex836
Copy link
Contributor

@mark-mxwl Apologies for the delay! We recently merged a PR that I believe resolves the issue this PR is attempting to fix. Many apologies for not being able to get to this sooner 💛

I'll go ahead and close out this PR, but please feel free to reopen / ping if needed!

@mark-mxwl
Copy link
Contributor Author

Np @nguyenalex836! Glad it got sorted. Appreciate the heads-up! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content This issue or pull request belongs to the Docs Content team developers Content related to developers github apps Content related to GitHub Apps needs SME This proposal needs review from a subject matter expert waiting for review Issue/PR is waiting for a writer's review
Projects
None yet
7 participants