-
-
Save koddsson/f9e3b07ad44eeaff3d2342c2be247f47 to your computer and use it in GitHub Desktop.
Simple Bash script that let's me post a micropub note from my terminal
This file contains hidden or 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
#! /bin/bash | |
ME="https://koddsson.com" | |
MICROPUB_ENDPOINT="$ME/micropub" | |
CODE=$(cat token) | |
STATUS_CODE=$(curl -sw '%{http_code}' -o /dev/null -d "code=$CODE&redirect_uri=http://nonexisting-domain.dev/callback&client_id=$ME" https://indieauth.com/auth) | |
if [ $STATUS_CODE -eq 404 ]; then | |
open "https://indieauth.com/auth?me=$ME&client_id=$ME&scope=create+update&response_type=code&redirect_uri=http%3A%2F%2Fnonexisting-domain.dev%2Fcallback" | |
echo "You need to get a new token" | |
exit 1 | |
fi | |
ACCESS_TOKEN=$(curl -s -H 'Accept: application/json' "https://tokens.indieauth.com/token" -d "code=$CODE&redirect_uri=http://nonexisting-domain.dev/callback&grant_type=authorization_code&client_id=$ME&me=$ME" | jq -r '.access_token') | |
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" -d "h=entry&content=$1" $MICROPUB_ENDPOINT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment