Skip to content

Commit 0ab8d82

Browse files
committed
fix: cast gh_app_id to string for JWT encoding compatibility
Relates to #508 ## What Cast gh_app_id to str() when passing it to login_as_app_installation, which internally calls jwt.encode expecting the iss claim to be a string. Updated tests to pass integer app IDs and assert the string conversion occurs. ## Why Since v2.0.0, GitHub App authentication fails with "TypeError: Issuer (iss) must be a string" because newer versions of PyJWT enforce that the iss claim is a string, but gh_app_id was being passed as an integer. ## Notes - Tests now use assert_called_once_with instead of assert_called_once to verify the exact arguments, preventing this class of regression - Test inputs changed from strings to integers to mirror real-world usage where env vars are parsed as ints Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent d2af62b commit 0ab8d82

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def auth_to_github(
3232
else:
3333
gh = github3.github.GitHub()
3434
gh.login_as_app_installation(
35-
gh_app_private_key_bytes, gh_app_id, gh_app_installation_id
35+
gh_app_private_key_bytes, str(gh_app_id), gh_app_installation_id
3636
)
3737
github_connection = gh
3838
elif ghe and token:

test_auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def test_auth_to_github_with_ghe_and_ghe_app(self, mock_ghe):
5656
mock = mock_ghe.return_value
5757
mock.login_as_app_installation = MagicMock(return_value=True)
5858
result = auth.auth_to_github(
59-
"", "123", "123", b"123", "https://github.example.com", True
59+
"", 123, 456, b"123", "https://github.example.com", True
6060
)
61-
mock.login_as_app_installation.assert_called_once()
61+
mock.login_as_app_installation.assert_called_once_with(b"123", "123", 456)
6262
self.assertEqual(result, mock)
6363

6464
@patch("github3.github.GitHub")
@@ -69,9 +69,9 @@ def test_auth_to_github_with_app(self, mock_gh):
6969
mock = mock_gh.return_value
7070
mock.login_as_app_installation = MagicMock(return_value=True)
7171
result = auth.auth_to_github(
72-
"", "123", "123", b"123", "https://github.example.com", False
72+
"", 123, 456, b"123", "https://github.example.com", False
7373
)
74-
mock.login_as_app_installation.assert_called_once()
74+
mock.login_as_app_installation.assert_called_once_with(b"123", "123", 456)
7575
self.assertEqual(result, mock)
7676

7777
@patch("github3.apps.create_jwt_headers", MagicMock(return_value="gh_token"))

0 commit comments

Comments
 (0)