Skip to content

Instantly share code, notes, and snippets.

@rctay
Created January 18, 2012 18:11
Show Gist options
  • Save rctay/1634597 to your computer and use it in GitHub Desktop.
Save rctay/1634597 to your computer and use it in GitHub Desktop.
[sh] get auth token for IVLE LAPI
#!/bin/sh
# user-specific info
API_KEY=
USER_ID="" # be careful about escaping!
PASSWORD="" # ditto
# add additional curl options here - eg. -v
CURL='curl'
# config
COOKIE_JAR=./ivle.cookies
LOGIN_URL="https://ivle.nus.edu.sg/api/login/?apikey=$API_KEY"
echo "getting cookie..."
viewstate=$(
$CURL "$LOGIN_URL" | \
awk '/name="__VIEWSTATE"/ { split($5,parts,"\""); print parts[2] }'
)
echo "logging in..."
token=$($CURL "$LOGIN_URL" \
-L \
-b "$COOKIE_JAR" -c "$COOKIE_JAR" \
--data-urlencode "__VIEWSTATE=$viewstate" \
--data-urlencode "userid=$USER_ID" \
--data-urlencode "password=$PASSWORD") \
|| printf >2 "failed to get token:\n%s" "$token" \
&& printf "your token is:\n%s\n" "$token"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment