Last active
November 13, 2022 09:32
-
-
Save lantrix/a5b0dcd5d109e84b30989434742c755f to your computer and use it in GitHub Desktop.
Generate a JWT from a GitHub App for REST API access by your App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install JWT Creator https://github.com/trstringer/jwt-creator | |
go install github.com/trstringer/jwt-creator@latest | |
# Download GitHub App Private Key as $HOME/app.pem | |
# https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#generating-a-private-key | |
# Generate public key from GitHub App Private Key | |
openssl rsa -in "$HOME/app.pem" -pubout -out "$HOME/app.pub" | |
# Generate JWT | |
APP_ID='123456' # ID Of installed App | |
PRIVATE_KEY_FILE="$HOME/app.pem" | |
PUBLIC_KEY_FILE="$HOME/app.pub" | |
GH_OAUTH_TOKEN=$(jwt-creator create --private-key-file $PRIVATE_KEY_FILE --issued-at-now --expires-in-seconds 300 --issuer $APP_ID) | |
# Optional verify | |
jwt-creator verify --public-key-file $PUBLIC_KEY_FILE --token $GH_OAUTH_TOKEN | |
# Use Token | |
curl -i -H "Authorization: Bearer ${GH_OAUTH_TOKEN}" -H "Accept: application/vnd.github+json" https://api.github.com/app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment