Skip to content

Instantly share code, notes, and snippets.

@utdemir
Last active December 22, 2019 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utdemir/31908eb85a3d01ca2860bdafe0a320c4 to your computer and use it in GitHub Desktop.
Save utdemir/31908eb85a3d01ca2860bdafe0a320c4 to your computer and use it in GitHub Desktop.
Tiny shellscript to authenticate to Pocket (getpocket.com).
#!/usr/bin/env bash
REDIRECT="http://127.0.0.1:7777"
echo "Enter your consumer key."
echo "You can get it from: https://getpocket.com/developer/apps/new"
read -p "> " consumer_key
code=$(
curl -sX POST --data "consumer_key=$consumer_key&redirect_uri=$REDIRECT" \
https://getpocket.com/v3/oauth/request |
grep -Po '(?<=code=)[^&]*')
echo "Open:"
echo " https://getpocket.com/auth/authorize?request_token=${code}&redirect_uri=$REDIRECT"
echo -ne 'HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 5\n\nDone.' |
nc -W 1 -l 7777 >/dev/null
echo "Callback received."
ret=$(curl --fail -sX POST --data "consumer_key=$consumer_key&code=$code" \
https://getpocket.com/v3/oauth/authorize)
user="$(echo "$ret" | grep -Po '(?<=username=)[^&]*')"
token="$(echo "$ret" | grep -Po '(?<=access_token=)[^&]*')"
echo "POCKET_USER=$user"
echo "POCKET_TOKEN=$token"
echo "POCKET_CONSUMER_KEY=$consumer_key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment