Skip to content

Commit

Permalink
Test commit to changed branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lagergren committed Nov 12, 2024
1 parent ed80674 commit e9779c1
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions bin/check-github-token-privileges.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
# it can be programmatically or manually double checked whether it only had the
# intended privileges. For example: no write privileges, and read:package only.

token=$1
if [ -z $token ]; then
echo "Missing argument: GitHub token to inspect."
else
curl -sS -f -I -H "Authorization: token $token" https://api.github.com | grep -i x-oauth-scopes
token="$1"
if [ -z "$token" ]; then
echo "Missing argument: GitHub token to inspect, e.g. '$0 \$GITHUB_TOKEN'"
exit 1
fi

output=$(curl -sS -f -I -H "Authorization: token $token" https://api.github.com)
if [ $? != 0 ]; then
echo "ERROR: curl failed to resolve token privileges for the given token. Is it valid?"
exit 1
fi

oauth_scopes=$(echo "$output" | grep -i x-oauth-scopes | grep -v ^access-control-expose-headers)
if [ -z "$oauth_scopes" ]; then
echo "ERROR: Failed to resolve token privileges from curl response."
exit 1
fi

echo "$oauth_scopes"

0 comments on commit e9779c1

Please sign in to comment.