0

I'm trying to authenticate to google app engine programmatically. I've tried the code sample from the "gae-app-manager" project but it fails:

tmp>java -jar net.sf.gae-app-manager-0.0.1-jar-with-dependencies.jar myaccount@gmail.com mypassword appname
Exception in thread "main" java.lang.Exception: Did not find ACSID cookie
        at net.sf.gaeappmanager.google.LogonHelper.loginToGoogleAppEngine(LogonHelper.java:85)
        at net.sf.gaeappmanager.google.appengine.Manager.retrieveAppQuotaDetails(Manager.java:34)
        at net.sf.gaeappmanager.google.appengine.Main.main(Main.java:55)

Any idea? I'm able to get the token, but there are no cookies. The code (taken from the gae-app-manager project - http://gae-app-manager.git.sourceforge.net/git/gitweb.cgi?p=gae-app-manager/gae-app-manager;a=blob;f=src/main/java/net/sf/gaeappmanager/google/LogonHelper.java;h=8e09a6d7f864c29b10847ac7fd2eeab2d3e561e6;hb=HEAD):

 List<NameValuePair> nvps = new ArrayList<NameValuePair>();
 nvps.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
 nvps.add(new BasicNameValuePair("Email", userid));
 nvps.add(new BasicNameValuePair("Passwd", password));
 nvps.add(new BasicNameValuePair("service", "ah"));
 nvps.add(new BasicNameValuePair("source", source));

 HttpPost post = new HttpPost(
                 "https://www.google.com/accounts/ClientLogin");
 post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

 HttpResponse response = client.execute(post);

 if (response.getStatusLine().getStatusCode() != 200) {
         throw new Exception("Error obtaining ACSID");
 }

 String authToken = getAuthToken(response.getEntity().getContent());

 post.abort();

 HttpGet get = new HttpGet(
                 "https://appengine.google.com/_ah/login?auth=" + authToken);

 response = client.execute(get);

 for (Cookie cookie : client.getCookieStore().getCookies()) {
         if (cookie.getName().startsWith("ACSID")) {
                 return cookie.getValue();
         }
 }

 get.abort();

 throw new Exception("Did not find ACSID cookie");

Thanks,

Li

Graham P Heath
  • 7,009
  • 3
  • 31
  • 45
Lin
  • 2,445
  • 5
  • 27
  • 37

2 Answers2

1

Have you considered using the OAuth support instead of trying to log in as a web client would? Every App Engine app can act as an OAuth provider with very little work required on the server side to set it up.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • I'll try OAuth as well - will it allow me to access any https site that I'm permitted to (like with the HttpClient), or is it limited to specific areas in GAE? thanks. – Lin Jun 16 '11 at 10:21
  • @Li I'm not sure I understand. You're trying to authenticate a client to App Engine, aren't you? What do other sites have to do with it? – Nick Johnson Jun 17 '11 at 00:28
  • I was wondering if I could use the same method to connect to gmail and other google subdomains. – Lin Jun 19 '11 at 18:35
  • @Li Only to services that support OAuth for their APIs. – Nick Johnson Jun 20 '11 at 00:42
0

To solve the problem use "SACSID" instead of "ACSID"

Lin
  • 2,445
  • 5
  • 27
  • 37