Skip to content

Commit

Permalink
Add script to generate JWT token for a Github App
Browse files Browse the repository at this point in the history
  • Loading branch information
stefaniuk committed Jul 31, 2023
1 parent 605019d commit a7d81d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions assets/30-install-developer-tools.macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ function tech-python-configure() {

python -m ensurepip
python -m pip install --upgrade pip
python -m pip install \
jwt

# TODO: Install dev tools for python
# brew $install \
Expand Down
35 changes: 35 additions & 0 deletions private_dot_local/bin/github-app-generate-jwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
import jwt
import time
import sys

# Get PEM file path
if len(sys.argv) > 1:
pem = sys.argv[1]
else:
pem = input("Enter path of private PEM file: ")

# Get the App ID
if len(sys.argv) > 2:
app_id = sys.argv[2]
else:
app_id = input("Enter your APP ID: ")

# Open PEM
with open(pem, 'rb') as pem_file:
signing_key = jwt.jwk_from_pem(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 identifier
'iss': app_id
}

# Create JWT
jwt_instance = jwt.JWT()
encoded_jwt = jwt_instance.encode(payload, signing_key, alg='RS256')

print(f"JWT: {encoded_jwt}")

0 comments on commit a7d81d0

Please sign in to comment.