Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

Commit 7d6ae91

Browse files
committed
Generate JWT allowing authentication
1 parent 6d20abe commit 7d6ae91

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ ipython = "*"
1515

1616
flask = "*"
1717
requests = "*"
18+
pyjwt = "*"
19+
cryptography = "*"

Pipfile.lock

Lines changed: 106 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf8 -*-
3+
4+
import os
5+
import time
6+
7+
import requests
8+
import jwt
9+
10+
11+
# Generate the JWT
12+
payload = {
13+
# issued at time
14+
'iat': int(time.time()),
15+
# JWT expiration time (10 minute maximum)
16+
'exp': int(time.time()) + (10 * 60),
17+
# GitHub App's identifier
18+
'iss': os.environ['APP_ID']
19+
}
20+
21+
with open(os.environ['PRIVATE_KEY_FILE']) as fp:
22+
private_key = fp.read()
23+
encoded = jwt.encode(payload, private_key, algorithm='RS256')
24+
25+
print "👋", encoded

env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
FLASK_APP=app/app.py
22
WEBHOOK_PROXY_URL=https://smee.io/XXXXXXXXXXXXXXX
3+
WEBHOOK_SECRET=development
4+
APP_ID=999999
5+
PRIVATE_KEY_FILE=your.private-key.pem

0 commit comments

Comments
 (0)