diff --git a/src/githubapp/core.py b/src/githubapp/core.py index 34517e3..944a2ab 100644 --- a/src/githubapp/core.py +++ b/src/githubapp/core.py @@ -576,8 +576,14 @@ def _create_jwt(self, expiration=60): :param expiration: int :return string: """ + if self.id is None: + raise GitHubAppError( + message="GitHub App ID (github_app_id) is not configured; cannot generate JWT.", + status=None, + data=None, + ) now = int(time.time()) - payload = {"iat": now, "exp": now + expiration, "iss": self.id} + payload = {"iat": now, "exp": now + expiration, "iss": str(self.id)} encrypted = jwt.encode(payload, key=self.key, algorithm="RS256") if isinstance(encrypted, bytes): diff --git a/tests/test_core.py b/tests/test_core.py index 5b53e24..adb048d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -202,7 +202,7 @@ def test_create_jwt_payload_structure(self, mock_time, mock_jwt): github_app = GitHubApp(github_app_id=123, github_app_key=b"test_key") github_app._create_jwt(expiration=300) - expected_payload = {"iat": 1640995200, "exp": 1640995200 + 300, "iss": 123} + expected_payload = {"iat": 1640995200, "exp": 1640995200 + 300, "iss": "123"} mock_jwt.encode.assert_called_once_with( expected_payload, key=b"test_key", algorithm="RS256" )