Skip to content

Instantly share code, notes, and snippets.

@jitran
Created April 5, 2024 02:46
Show Gist options
  • Save jitran/df20608b044c3eed5696ea13e9bae604 to your computer and use it in GitHub Desktop.
Save jitran/df20608b044c3eed5696ea13e9bae604 to your computer and use it in GitHub Desktop.
GitHub App - Installation Access Token

Install the gh-token extension

gh extension install Link-/gh-token

Retrieve the installation access token for your GitHub App

APP_ID=<APP ID>
PRIVATE_KEY=<PATH TO PRIVATE KEY>
INSTALLATION_ID=$(gh token installations --app-id $APP_ID --key $PRIVATE_KEY | jq '.[] | .id')
TOKEN=$(gh token generate --app-id $APP_ID --key $PRIVATE_KEY --installation-id $INSTALLATION_ID | jq -r '.token')

Validate the token and ensure the login value ends with [bot]

curl -H "Authorization: bearer $TOKEN" -X POST -d " \
 { \
   \"query\": \"query { viewer { login }}\" \
 } \
" https://api.github.com/graphql

Clone a repo with the installation access token

git clone https://x-access-token:$TOKEN@github.com/<org|owner>/<repo>.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment