Skip to content

Commit fc41784

Browse files
authored
Merge pull request #1071 from davisagli/pyjwt
Sign JWTs for github app auth using PyJWT instead of jwcrypto
2 parents be71aba + 3d89c29 commit fc41784

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,5 @@ Contributors
208208
- Gunnar Andersson (@gunnarx)
209209

210210
- Thomas Lam (@lamcw)
211+
212+
- David Glick (@davisagli)

README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ Dependencies
1818

1919
- requests_
2020
- uritemplate_
21+
- python-dateutil_
22+
- PyJWT_
2123

2224
.. _requests: https://github.com/kennethreitz/requests
2325
.. _uritemplate: https://github.com/sigmavirus24/uritemplate
26+
.. _python-dateutil: https://github.com/dateutil/dateutil
27+
.. _PyJWT: https://github.com/jpadilla/pyjwt
28+
2429

2530
Contributing
2631
------------
@@ -45,13 +50,11 @@ this in a virtual environment. These need to be installed for the tests to run.
4550
Build status
4651
~~~~~~~~~~~~
4752

48-
You can find `master` build statuses for different environments.
53+
You can find build statuses for different environments.
4954

5055
- Github_
51-
- appveyor_
5256

5357
.. _Github: https://github.com/sigmavirus24/github3.py/actions
54-
.. _appveyor: https://ci.appveyor.com/project/sigmavirus24/github3-py/branch/master
5558

5659
License
5760
-------

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ requires_dist =
2727
requests>=2.0
2828
uritemplate>=3.0.0
2929
python-dateutil>=2.6.0
30-
jwcrypto>=0.5.0
30+
PyJWT>=2.3.0
3131

3232
[options]
3333
packages = find:
3434
install_requires =
35-
jwcrypto>=0.5.0
35+
PyJWT>=2.3.0
3636
python-dateutil>=2.6.0
3737
requests>=2.18
3838
uritemplate>=3.0.0

src/github3/apps.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"""
55
import time
66

7-
from jwcrypto import jwk
8-
from jwcrypto import jwt
7+
import jwt
98

109
from . import models
1110
from . import users
@@ -155,10 +154,6 @@ def _update_attributes(self, json):
155154
self.updated_at = self._strptime(json["updated_at"])
156155

157156

158-
def _load_private_key(pem_key_bytes):
159-
return jwk.JWK.from_pem(pem_key_bytes)
160-
161-
162157
def create_token(private_key_pem, app_id, expire_in=TEN_MINUTES_AS_SECONDS):
163158
"""Create an encrypted token for the specified App.
164159
@@ -176,15 +171,13 @@ def create_token(private_key_pem, app_id, expire_in=TEN_MINUTES_AS_SECONDS):
176171
"""
177172
if not isinstance(private_key_pem, bytes):
178173
raise ValueError('"private_key_pem" parameter must be byte-string')
179-
key = _load_private_key(private_key_pem)
180174
now = int(time.time())
181-
token = jwt.JWT(
182-
header={"alg": "RS256"},
183-
claims={"iat": now, "exp": now + expire_in, "iss": app_id},
184-
algs=["RS256"],
175+
token = jwt.encode(
176+
payload={"iat": now, "exp": now + expire_in, "iss": app_id},
177+
key=private_key_pem,
178+
algorithm="RS256",
185179
)
186-
token.make_signed_token(key)
187-
return token.serialize()
180+
return token
188181

189182

190183
def create_jwt_headers(

0 commit comments

Comments
 (0)