Created
January 18, 2012 18:11
-
-
Save rctay/1634597 to your computer and use it in GitHub Desktop.
[sh] get auth token for IVLE LAPI
This file contains 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/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