Skip to content

Commit 8deb13d

Browse files
committed
Improve bash implementation
1 parent 24522ce commit 8deb13d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/client_bash_auth.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22

3-
# login and store cookies in 'cookies.txt'
4-
curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt --silent >/dev/null
3+
# login and store cookies in 'cookies.txt' AND retrieve the value of the XSRF token
4+
TOKEN=`curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt`
55

6-
# retrieve the value of the 'XSRF-TOKEN' cookie
7-
TOKEN=`cat cookies.txt|grep XSRF-TOKEN|cut -f 7`
6+
# strip the double quotes from the variable (JSON decode)
7+
TOKEN=${TOKEN//\"/}
88

9-
# set the 'XSRF-TOKEN' as the 'X-XSRF-Token' header AND send the cookies to the server
9+
# set the XSRF token as the 'X-XSRF-Token' header AND send the cookies to the server
1010
curl 'http://localhost/api.php/posts?include=categories,tags,comments&filter=id,eq,1' --header "X-XSRF-Token: $TOKEN" --cookie cookies.txt
1111

1212
# clean up

0 commit comments

Comments
 (0)