Skip to content

Instantly share code, notes, and snippets.

@whiteinge
Created January 30, 2020 03:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save whiteinge/946ae5ec0cc58b845c2212a78bf3cea4 to your computer and use it in GitHub Desktop.
Save whiteinge/946ae5ec0cc58b845c2212a78bf3cea4 to your computer and use it in GitHub Desktop.
Wrapper to fetch CSRF token and authenticate via the login page
#!/usr/bin/env sh
# Wrapper to fetch CSRF token and authenticate via the login page
url='http://localhost:3002'
login="${url}/sign_in"
curl -sS -c cookies.txt "$login" |
htmlstar sel -t -v "//_:input[@name='csrf_token']/@value" -o '
' | xargs -I{} curl -sS -c cookies.txt -b cookies.txt "$login" \
--data-urlencode 'user[email]=me@example.com' \
--data-urlencode 'user[password]=password' \
--data-urlencode 'csrf_token={}' \
-o /dev/null
curl -sS -b cookies.txt -c cookies.txt "$url" -o /dev/null \
-w '%{http_code}\n' | xargs test 200 -eq \
&& printf 'Logged in.\n' 1>&2
tmux send "c -b cookies.txt -c cookies.txt ${url}/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment