Skip to content

Instantly share code, notes, and snippets.

@kyanny
Last active December 9, 2021 16:58
Show Gist options
  • Select an option

  • Save kyanny/f4b4be2d7fb35141c0dc4919724bb107 to your computer and use it in GitHub Desktop.

Select an option

Save kyanny/f4b4be2d7fb35141c0dc4919724bb107 to your computer and use it in GitHub Desktop.

Revisions

  1. kyanny revised this gist Dec 9, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions github-apps-call-rest-api.sh
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ app_id=157615
    private_key_file=my-tiny-github-app.2021-12-09.private-key.pem

    exp=$(date -d '10 minutes' +%s)
    # If your machine doesn't have GNU date command, uncomment below
    # exp=$(perl -e 'print time + 60*10')
    JWT=$(./jwt encode --alg RS256 --exp $exp --iss $app_id --secret @$private_key_file)

    curl -i -H "Authorization: Bearer $JWT" https://api.github.com/app
  2. kyanny created this gist Dec 9, 2021.
    25 changes: 25 additions & 0 deletions github-apps-call-rest-api.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash
    curl -sLO https://github.com/mike-engel/jwt-cli/releases/latest/download/jwt-linux.tar.gz
    tar xzf jwt-linux.tar.gz

    curl -sLO https://github.com/stedolan/jq/releases/latest/download/jq-linux64
    mv jq-linux64 jq
    chmod +x jq

    app_id=157615
    private_key_file=my-tiny-github-app.2021-12-09.private-key.pem

    exp=$(date -d '10 minutes' +%s)
    JWT=$(./jwt encode --alg RS256 --exp $exp --iss $app_id --secret @$private_key_file)

    curl -i -H "Authorization: Bearer $JWT" https://api.github.com/app

    curl -i -H "Authorization: Bearer $JWT" https://api.github.com/app/installations
    curl -H "Authorization: Bearer $JWT" https://api.github.com/app/installations > installations.json
    access_tokens_url=$(./jq -r '.[].access_tokens_url' installations.json)

    curl -i -X POST -H "Authorization: Bearer $JWT" $access_tokens_url
    curl -X POST -H "Authorization: Bearer $JWT" $access_tokens_url > access_tokens.json
    access_token=$(./jq -r '.token' access_tokens.json)

    curl -H "Authorization: token $access_token" https://api.github.com/repos/kyanny/test/issues | ./jq '.[].title'