You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/developers/apps/building-github-apps/authenticating-with-github-apps.md
+16-7Lines changed: 16 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -98,36 +98,45 @@ puts jwt
98
98
99
99
#### Using Python
100
100
101
-
Here is a similar script forgenerating a JWTin Python. Note you will have to use `pip install jwt`in order to use this script. This script will prompt you forthe location of your PEM file, or you can pass it as an inline argument when you execute the script. Replace `YOUR_APP_ID` with the ID of your app. Make sure to enclose the valuein single quotes.
101
+
Here is a similar script forgenerating a JWTin Python. Note you will have to use `pip install jwt`in order to use this script. This script will prompt you for the location of your PEM file and your app's ID, or you can pass them as inline arguments when you execute the script.
102
102
103
103
```python{:copy}
104
+
#!/usr/bin/env python3
104
105
import jwt
105
106
import time
106
107
import sys
107
108
109
+
108
110
# Get PEM file path
109
111
if len(sys.argv) > 1:
110
112
pem = sys.argv[1]
111
113
else:
112
114
pem = input("Enter path of private PEM file: ")
113
115
116
+
# Get the App ID
117
+
if len(sys.argv) > 2:
118
+
app_id = sys.argv[2]
119
+
else:
120
+
app_id = input("Enter your APP ID: ")
121
+
114
122
# Open PEM
115
-
with open(pem, 'r') as pem_file:
116
-
signing_key = pem_file.read()
123
+
with open(pem, 'rb') as pem_file:
124
+
signing_key = jwt.jwk_from_pem(pem_file.read())
117
125
118
126
payload = {
119
127
# Issued at time
120
128
'iat': int(time.time()),
121
129
# JWT expiration time (10 minutes maximum)
122
130
'exp': int(time.time()) + 600,
123
-
#{% data variables.product.prodname_github_app %}'s identifier
Use your {% data variables.product.prodname_github_app %}'s identifier (`YOUR_APP_ID`) as the value for the JWT [iss](https://tools.ietf.org/html/rfc7519#section-4.1.1) (issuer) claim. You can obtain the {% data variables.product.prodname_github_app %} identifier via the initial webhook ping after [creating the app](/apps/building-github-apps/creating-a-github-app/), or at any time from the app settings page in the GitHub.com UI.
0 commit comments