Created
July 30, 2025 12:13
-
-
Save jenrik/e6651553349076952885e21bae1c2ac6 to your computer and use it in GitHub Desktop.
Generate signed JWT for a Github App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import sys | |
| import time | |
| import jwt | |
| # Get PEM file path | |
| if len(sys.argv) > 1: | |
| pem = sys.argv[1] | |
| else: | |
| pem = input("Enter path of private PEM file: ") | |
| # Get the Client ID | |
| if len(sys.argv) > 2: | |
| client_id = sys.argv[2] | |
| else: | |
| client_id = input("Enter your Client ID: ") | |
| # Open PEM | |
| with open(pem, 'rb') as pem_file: | |
| signing_key = pem_file.read() | |
| payload = { | |
| # Issued at time | |
| 'iat': int(time.time()), | |
| # JWT expiration time (10 minutes maximum) | |
| 'exp': int(time.time()) + 600, | |
| # GitHub App's client ID | |
| 'iss': client_id | |
| } | |
| # Create JWT | |
| encoded_jwt = jwt.encode(payload, signing_key, algorithm='RS256') | |
| print(encoded_jwt, end="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment