diff --git a/examples/client_bash_auth.sh b/examples/client_bash_auth.sh index 8224900..880355a 100644 --- a/examples/client_bash_auth.sh +++ b/examples/client_bash_auth.sh @@ -1,12 +1,12 @@ #!/bin/bash -# login and store cookies in 'cookies.txt' -curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt --silent >/dev/null +# login and store cookies in 'cookies.txt' AND retrieve the value of the XSRF token +TOKEN=`curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt` -# retrieve the value of the 'XSRF-TOKEN' cookie -TOKEN=`cat cookies.txt|grep XSRF-TOKEN|cut -f 7` +# strip the double quotes from the variable (JSON decode) +TOKEN=${TOKEN//\"/} -# set the 'XSRF-TOKEN' as the 'X-XSRF-Token' header AND send the cookies to the server +# set the XSRF token as the 'X-XSRF-Token' header AND send the cookies to the server curl 'http://localhost/api.php/posts?include=categories,tags,comments&filter=id,eq,1' --header "X-XSRF-Token: $TOKEN" --cookie cookies.txt # clean up