Skip to content

fix python example in generating-a-json-web-token-jwt-for-a-github-app #39409

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

Closed
wants to merge 2 commits into from

Conversation

gregsadetsky
Copy link

Why:

Closes: #39408

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

the python example has been fixed

Check off the following:

  • A subject matter expert (SME) has reviewed the technical accuracy of the content in this PR. In most cases, the author can be the SME. Open source contributions may require an SME review from GitHub staff.
  • The changes in this PR meet the docs fundamentals that are required for all content.
  • All CI checks are passing and the changes look good in the review environment.

@Copilot Copilot AI review requested due to automatic review settings July 19, 2025 23:59
Copy link

welcome bot commented Jul 19, 2025

Thanks for opening this pull request! A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the Python code example in the GitHub App JWT generation documentation to use the correct PyJWT library API. The changes update the outdated jwt module usage to the modern JWT class-based approach with proper key handling.

Key changes:

  • Updates import statement to use the modern JWT class and jwk_from_pem function
  • Modifies key loading to use jwk_from_pem for proper PEM file handling
  • Changes JWT encoding to use the instance-based approach with updated parameter names

@@ -115,7 +115,8 @@ payload = {
}

# Create JWT
encoded_jwt = jwt.encode(payload, signing_key, algorithm='RS256')
instance = JWT()
Copy link
Preview

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name change from 'algorithm' to 'alg' should be documented or explained in the surrounding text to help users understand why this change was made, especially since this differs from the previous API.

Suggested change
instance = JWT()
instance = JWT()
# The 'alg' parameter specifies the algorithm used for signing the JWT.
# It corresponds to the 'algorithm' parameter in the previous API.

Copilot uses AI. Check for mistakes.

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

github-actions bot commented Jul 20, 2025

How to review these changes 👓

Thank you for your contribution. To review these changes, choose one of the following options:

A Hubber will need to deploy your changes internally to review.

Table of review links

Note: Please update the URL for your staging server or codespace.

The table shows the files in the content directory that were changed in this pull request. This helps you review your changes on a staging server. Changes to the data directory are not included in this table.

Source Review 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.17 3.16 3.15 3.14
fpt
ghec
ghes@ 3.17 3.16 3.15 3.14

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

🤖 This comment is automatically generated.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Jul 20, 2025
@Sharra-writes
Copy link
Contributor

@gregsadetsky Thanks for opening an issue and PR! I'll get this triaged for review.

@Sharra-writes Sharra-writes added content This issue or pull request belongs to the Docs Content team github apps Content related to GitHub Apps and removed triage Do not begin working on this issue until triaged by the team labels Jul 21, 2025
Kingparis1

This comment was marked as spam.

@Sharra-writes
Copy link
Contributor

@gregsadetsky My co-worker tells me this is essentially a reversion to an earlier state, but agrees it's not a bad move currently. The only thing is that on line 79, the pip install PyJWT cryptography should actually read pip install pyjwt cryptography. Just that first instance needs to be all lowercase. Would you be willing to make that change so I don't have to open a separate PR for it?

@gregsadetsky
Copy link
Author

@Sharra-writes oh my God, this is super embarrassing ... I actually didn't fully follow the original tutorial and used a different jwt library.

The library that you're using seems a lot more standard. And so, the example in the docs wasn't wrong at all...

I'm really sorry! I'll just close this PR then, yeah?

@Sharra-writes
Copy link
Contributor

@gregsadetsky It's no problem! I can close it for you. Thanks for reaching out to improve things, even if it went a bit sideways this time. We still appreciate the effort and concern.

@gregsadetsky
Copy link
Author

A good slice of humble pie for me! Haha. Cheers & thank you

@Kingparis1

This comment was marked as spam.

@Asad-Mirza-24

This comment was marked as spam.

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 github apps Content related to GitHub Apps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Example: Using Python to generate a JWT" does not work
4 participants