Selaa lähdekoodia

Improve bash implementation

Maurits van der Schee 7 vuotta sitten
vanhempi
commit
8deb13d824
1 muutettua tiedostoa jossa 5 lisäystä ja 5 poistoa
  1. 5
    5
      examples/client_bash_auth.sh

+ 5
- 5
examples/client_bash_auth.sh Näytä tiedosto

@@ -1,12 +1,12 @@
1 1
 #!/bin/bash
2 2
 
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`
5 5
 
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//\"/}
8 8
 
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
10 10
 curl 'http://localhost/api.php/posts?include=categories,tags,comments&filter=id,eq,1' --header "X-XSRF-Token: $TOKEN" --cookie cookies.txt
11 11
 
12 12
 # clean up

Loading…
Peruuta
Tallenna