Friday, April 09, 2010

Authenticating Google App Engine apps using curl

I'm going to show here the exact way that i use to authenticate to my google app engine application using unix script and curl.

This is a 3 steps process:
  1. Get the auth code from google (using ClientLogin)
  2. Get the cookie from google using the auth code
  3. Access the service that we want in google app
In the example we will use:
  • Application name is: MyFirstApp
  • Application url is:
  • Our application service name is: getAllData
  • Application admin is:
  • Application admin password is: adminadmin
Step 1:
Getting auth key:
curl -f -s --output myAuthFile.txt -d -d Passwd=adminadmin -d accountType=GOOGLE -d service=ah -d source=MyFirstApp
 after the command completes we will have a file named: myAuthFile.txt with 3 lines, the line that starts with "Auth=" is the auth code line, we will use this code in the next step.

Step 2:
Getting application cookie:
curl -c cookiefile "`cat myAuthFile.txt | grep ^Auth= | cut -d= -f2`" > /dev/null
after the command completes we will have a file named: cookiefile that will include our cookie, we will use the cookie in the next step.

Step 3:
Calling our application service, getAllData:
curl -f -s -H "Cookie: ACSID=`cat cookiefile | grep -v ^# | grep -v ^$|cut -f7`"

That's all!
Hope it will help anyone.


Anonymous said...

Thanks Oded! Yes, helped a lot! Thanks a lot for posting this. Cheers Josh

陳金進 said...

Thank you very much....

Anonymous said...

Huge help! Thanks a ton!