I wanted to execute one API using the command line but need to pass Cookie: JSESSIONID=<>; auth_cookie=<> value while executing it. We have CAS authentication for the target API.
Please let me know the curl or another command to get Cookie: JSESSIONID=<>; auth_cookie=<> value so I can pass it while executing API.
I have tried with
curl -v -s --cacert /etc/ssl/certs/cacert.crt https://example.com/login -c cookiefile -d "user=user1@domain.com&password=xxxx" -X POST
But it is just storing JSESSIONID in the cookie file. In browser login https://example.com/login
will redirect to CAS server login page after authentication it will redirect to https://example.com/index
I followed the approach given by @HBruijn.
ENCODED_DEST=`echo "https://example.com/login/login" | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' | sed 's/%2E/./g' | sed 's/%0A//g'`
CAS_ID=`curl -L -s --cacert /etc/ssl/certs/cacertga.crt -c $COOKIE_JAR https://cas-server.example2.com/cas/login?service=$ENCODED_DEST | grep name=.lt | sed 's/.*value..//' | sed 's/\".*//'`
This CAS_ID and JSESSIONID need to use in next call
curl -L -s --cacert /etc/ssl/certs/cacertga.crt --data "username=$USERNAME&password=$PASSWORD<=$CAS_ID&execution=e1s1&_eventId=submit" -i -b $COOKIE_JAR -c $COOKIE_JAR https://cas-server.example2.com/cas/login?service=$ENCODED_DEST -D .header.txt -o /dev/null
and finally .header.txt should have location URL appending with ticket id. Need to do final call on that location to get auth_cookie. But in my case, it is not giving location URL itself.
I refer solution here
I am editing this question, As I got a solution using python. Use mechanize.Browser() and it will easy to get require auth cookie.
Best Answer
The fact that you need to log in first before you can access the API means that a single curl request is probably not sufficient.
You probably need a script with multiple
curl
requests and work flow similar to:Or
die();
The standard Chrome developer tools plugin can standard help you to create the basis for such a curl script with the Copy All as cURL option in the network console.