Skip to content

fix: cast JWT iss claim to string for PyJWT 2.12+ compatibility#6

Merged
primetheus merged 3 commits into
mainfrom
fix/jwt-iss-string-type
Mar 20, 2026
Merged

fix: cast JWT iss claim to string for PyJWT 2.12+ compatibility#6
primetheus merged 3 commits into
mainfrom
fix/jwt-iss-string-type

Conversation

@primetheus
Copy link
Copy Markdown
Owner

Summary

  • Cast self.id to str() in _create_jwt() payload to satisfy PyJWT 2.12+ type enforcement on the iss claim
  • Update test expectation to match

Context

PyJWT 2.12+ enforces that the iss (issuer) claim must be a string, per RFC 7519 Section 4.1.1 (StringOrURI). Previously self.id (an int from github_app_id) was passed directly, which worked with older PyJWT versions but fails with:

TypeError: Issuer (iss) must be a string.

Why this is safe

  • Older PyJWT versions accept both int and str for iss — no breakage
  • GitHub's API matches the app ID by value regardless of JSON type (12345 vs "12345")
  • RFC 7519 defines iss as StringOrURI — string is the correct type

Test plan

  • Updated test_create_jwt_payload_structure to expect "iss": "123" instead of "iss": 123
  • Verified PyJWT 2.12.1 accepts the change
  • Verified older PyJWT behavior is unaffected (string is valid in all versions)

PyJWT 2.12+ enforces that the 'iss' claim must be a string per RFC 7519
Section 4.1.1 (StringOrURI). Previously self.id (an int) was passed
directly, which worked with older PyJWT but fails with:

    TypeError: Issuer (iss) must be a string.

This is safe for all PyJWT versions — older versions accept both int and
str, and GitHub's API matches on value regardless of JSON type.
Copilot AI review requested due to automatic review settings March 20, 2026 16:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates JWT generation in GitHubApp to ensure the iss (issuer) claim is always a string, maintaining compatibility with PyJWT 2.12+’s stricter claim type enforcement.

Changes:

  • Cast self.id to str when building the JWT payload (iss claim).
  • Update the unit test to expect "iss": "123" instead of an integer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/githubapp/core.py Ensures JWT iss claim is encoded as a string for PyJWT 2.12+ compatibility.
tests/test_core.py Updates JWT payload assertion to match the new iss string type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/githubapp/core.py
Addresses review feedback — str(None) would produce 'None' as the
issuer, which passes PyJWT's type check but gets rejected by GitHub.
Raise GitHubAppError with a clear message instead.
@primetheus primetheus merged commit 32985a9 into main Mar 20, 2026
7 checks passed
@primetheus primetheus deleted the fix/jwt-iss-string-type branch March 20, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants