Make-jwt.py: Difference between revisions
Jump to navigation
Jump to search
(Created page with "GitHub Make JWT Token Script == make-jwt.py == <pre> #!/usr/bin/env python3 # pip install jwt import jwt import time import sys # Get PEM file path if len(sys.argv) > 1:...") |
(No difference)
|
Latest revision as of 20:12, 1 December 2023
GitHub Make JWT Token Script
make-jwt.py
#!/usr/bin/env python3
# pip install jwt
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()),
'iat': int(time.time()) - 60, # flex for clock drift
# JWT expiration time (10 minutes maximum)
'exp': int(time.time()) + 50,
# 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}")
print("{}".format(encoded_jwt))
Original
#!/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}")