Saturday, May 16, 2009

Google App Engine + GData API + GApps Premier

There are a couple of things you need to be aware of if you are planning to develop applications running on App Engine that use the GData API's to talk to Google Enterprise Apps;

1. The GData API's appear to have a dependency on Goolge Collections;

http://code.google.com/p/google-collections/

If you are using certain API's and you get an error saying that a common Maps class cannot be instantiated, it is because you are missing this dependency.

2. The User Service cannot currently be used for Hosted GApps accounts. You have to use AuthSub. To get this to work you need to;

Add the following into you appengine xml file;

sessions-enabled true

system-properties property name="com.google.gdata.DisableCookieHandler" value="true"


3. If you want to use the Contacts API, then you need to set your session token on the ContactsService using setAuthSubToken(token, PRIVATE_KEY); if you are not using signed auth then set the PRIVATE_KEY to null. If you try to pass the token in the constructor or via the SetAuthSubToken(token) method you currently get an error saying that the Auth Header is missing.

4. When you upload your app to App Engine, you need to reset your browser (clear cookies, cache etc.) and you also need to wait a few minutes or more depending on the size of your app as there is a lag between upload completing and the new app version being deployed. If you test to quickly you appear to get your old code executing.

5. You cannot write files, spawn threads or open network connections on App Engine.

5 comments:

J5 said...

Thanks for the info.

bprotas said...

Can you expand on #3? Where do you get the token for setAuthSubToken?

Justin Brister said...

You can find more information on using AuthSub here:

http://code.google.com/apis/gdata/authsub.html

J

bprotas said...

So is there any way if I'm using the app engine's login mechanism, which already forces users to enter their gmail username and password, to use that same username/pw they entered with the GData APIs? Or do they have to login twice (once using App Engine's user service, and again with AuthSub)?

Justin Brister said...

Don't use the GAE User Service, just use AuthSub:

AuthSubManager authSubManager = new AuthSubManager(req, resp, hosted_domain);

if (authSubManager.isSignedIn(true) == false) {
resp.sendRedirect((authSubManager.getSigninUrl()));
}

This creates a Session token that you then use.

This allows you to use any Google Apps account, i.e. Consumer, ISP, Premier.

For what I am doing I use premier accounts. That way if the user does not have an account in my Private Google Apps domain (identified by the hosted_domain param), he can't access my service.

If you are going to use the public google accounts (consumer) then you will need to maintain a list of approved users and perform that check when the user authenticates as well, or allow all consumers to access your service.

I hope this helps.

J

Post a Comment