Skip to content

Commit b7cf611

Browse files
8R0WNI3sigmavirus24
authored andcommitted
Cast GitHub app_id as string before using as iss
The pyjwt library expects the issuer to be of type `str` and enforces it with jpadilla/pyjwt#1040. Using an integer as done before will result in `TypeError: Issuer (iss) must be a string.`. Signed-off-by: Jonas Brand (8R0WNI3) <j.brand@sap.com>
1 parent 880e6c2 commit b7cf611

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/github3/apps.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ def create_token(private_key_pem, app_id, expire_in=TEN_MINUTES_AS_SECONDS):
160160
161161
:param bytes private_key_pem:
162162
The bytes of the private key for this GitHub Application.
163-
:param int app_id:
164-
The integer identifier for this GitHub Application.
163+
:param int|str app_id:
164+
The identifier for this GitHub Application. Previously this
165+
was documented as an ``int``, however, PyJWT now requires it to be
166+
a ``str`` so we are accepting both. In both cases it will be
167+
coerced to a ``str``. We will *not* accept bytes and passing bytes
168+
is expected to fail.
165169
:param int expire_in:
166170
The length in seconds for this token to be valid for.
167171
Default: 600 seconds (10 minutes)
@@ -174,7 +178,7 @@ def create_token(private_key_pem, app_id, expire_in=TEN_MINUTES_AS_SECONDS):
174178
raise ValueError('"private_key_pem" parameter must be byte-string')
175179
now = int(time.time())
176180
token = jwt.encode(
177-
payload={"iat": now, "exp": now + expire_in, "iss": app_id},
181+
payload={"iat": now, "exp": now + expire_in, "iss": str(app_id)},
178182
key=private_key_pem,
179183
algorithm="RS256",
180184
)

0 commit comments

Comments
 (0)