How to get a patch/diff for a private repo commit

How can I get the patch/diff text of a commit from a private repo? I have a use case where I need access to the contents of specific Git objects in specific private repos.

For a public repo, I can take the commit URL and add .patch to then end to get the patch text (example). But for a private repo, the {URL}.patch is not found.

To demonstrate that the private .patch is not found:

I have an authenticated GitHub app with permissions to access the repo and have created a JWT as per the guidelines under Authenticating with GitHub Apps | GitHub Developer Guide:

curl -i -H "Authorization: Bearer $JWT" \
    -H "Accept: application/vnd.github.v3.patch" \
    https://api.github.com/repos/$OWNER/$PRIVATE_REPO/git/commits/$COMMIT_SHA

Returns a 200 with information about the patch.

curl -i -H "Authorization: Bearer $JWT" \
    -H "Accept: application/text" \
https://github.com/$OWNER/$PUBLIC_REPO/commit/$COMMIT_SHA.patch

Returns a 200 with the patch text for a public repo.

curl -i -H "Authorization: Bearer $JWT" \
    -H "Accept: application/vnd.github.v3.patch" \
    https://github.com/$OWNER/$PRIVATE_REPO/commit/$COMMIT_SHA.patch

Returns a 404 Not Found when requesting the {URL}.patch for a private repo. I understand the token doesn’t work because the request is not going through the API, but you get the idea of what I’d like to do.

QUESTIONS

  • Is there a way to authenticate a request to a git patch/diff in a private repo?
  • Is there another way to get a patch or diff in text form from a private repo using the API?