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.