Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace escaped newlines with actual newlines in privateKey values #96

Merged
merged 2 commits into from
Apr 29, 2024

Conversation

gr2m
Copy link
Owner

@gr2m gr2m commented Apr 29, 2024

Implements automatic newline conversion for private keys and updates documentation accordingly.

  • Code Update: Modifies index.js to automatically replace escaped newlines (\\n) in the privateKey argument with actual newline characters before passing it to the getToken() function. This ensures compatibility with private keys defined in environment variables or other sources where newlines are escaped.
  • Documentation Update: Enhances the README.md file by adding a note under the options.privateKey section. It now informs users that escaped newlines in the private key will be automatically replaced with actual newline characters, accommodating private keys stored with escaped newlines.

For more details, open the Copilot Workspace session.

@gr2m
Copy link
Owner Author

gr2m commented Apr 29, 2024

fyi this is the first pull request I generated using a Copilot Workspace. Other than generating a test file, it's a pretty great start!

@gr2m gr2m changed the title Replace escaped newlines with actual newlines in privateKey values fix: replace escaped newlines with actual newlines in privateKey values Apr 29, 2024
@gr2m
Copy link
Owner Author

gr2m commented Apr 29, 2024

also fyi I ran into this so often, and so others run into this even more, that I decided to just go ahead and implement this convenience fix. I'm not sure about the performance implications, if necessary we could check a subset of the private key string instead all of it, but I'd expect the performance implications to be negligible

@gr2m gr2m merged commit e1e8d57 into main Apr 29, 2024
3 checks passed
@gr2m gr2m deleted the fix-newlines branch April 29, 2024 22:45
Copy link

🎉 This PR is included in version 2.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

feedmypixel added a commit to DEFRA/cdp-self-service-ops that referenced this pull request Jan 22, 2025
So with the bump of @octokit/auth-app from v6.* -> v7.* it bumped its
own dependency of universal-github-app-jwt from v1.* -> v2.*

The universal-github-app-jwt v2 has introduced some work that replaces
newlines within private keys - https://github.com/gr2m/universal-github-app-jwt/blob/d52064d3395a02363b6f80afeeb5d91e0a5f2040/index.js#L17

This work looks like it came in in v2.1.1 - gr2m/universal-github-app-jwt#96

Essentially what this means is with the latest version the privateKey
must be a string rather than a buffer.

This code fixes this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant