Skip to content

Commit 0bd25bd

Browse files
authored
Add OAuth Token Authorization
Add OAuth Token Authorization to support 2-factor protected account.
1 parent 97da6d1 commit 0bd25bd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

create-gist.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ USAGE
2424
FNAME="${1:-}"
2525
if [[ -f "$FNAME" ]]; then
2626
CONTENT=$(cat "$FNAME")
27-
GITHUB_USERNAME="${2:-}"
27+
GITHUB_TOKEN="${2:-}"
2828
else
2929
CONTENT=$(timeout 2 cat -)
30-
GITHUB_USERNAME="${1-}"
30+
GITHUB_TOKEN="${1-}"
3131
FNAME="stdin"
3232
if [[ "$CONTENT" == "" ]]; then
3333
print_usage
@@ -36,7 +36,7 @@ else
3636
fi
3737

3838
# Github does not permit anonymous uploads since April 2018
39-
if [[ -z $GITHUB_USERNAME ]]; then
39+
if [[ -z $GITHUB_TOKEN ]]; then
4040
print_usage
4141
exit 2
4242
fi
@@ -68,7 +68,7 @@ cat > $tmp_file <<EOF
6868
EOF
6969

7070
# 4. Use curl to make a POST request
71-
OUTPUT=$(curl -u ${GITHUB_USERNAME} -X POST -d @$tmp_file "https://api.github.com/gists")
71+
OUTPUT=$(curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d @$tmp_file "https://api.github.com/gists")
7272
uploaded_url=$(echo "$OUTPUT" | grep 'html_url' | grep 'gist')
7373

7474
# 5. cleanup the tmp file

0 commit comments

Comments
 (0)