Home » Odeon Blogs » Tudor, UI/UX Maestro »

Facebook Connect in Google App Engine. Making the cloud sociable

Facebook Connect in Google App Engine. Making the cloud sociable

Socialble CloudGoogle App Engine is great for fast deploying and fast scaling applications. That’s a fact. The default authentication system uses Google accounts. Another option is deploying a custom user/password combination, which is the more traditional approach.

For one of our recent projects, we wanted to make the user authentication even simpler, so we integrated Facebook Connect and the Graph API. Now users can login with only one click, if they are already logged into Facebook. 

Another advantage of using this approach is avoiding boring registration forms. One click on the blue Facebook button and you’re done. User info is retrieved from Facebook, after granting the appropriate permission.

Integration

As in the past, we’ve used Kay Framework to help with some of the lower-level tasks on Google App Engine. Kay already comes with it’s own username/password authentication system, aside from the Google Accounts one. Mimicking the existing back-end, we wrote a simple one, based only on the Facebook User ID.

Facebook uses OAuth 2.0, which is token based. The token is obtained from a short “chat” between Google Appengine and the Facebook Server.

Graph API

After authenticating, using the token we can make any requests to the Graph API. Examples: retrieving user info, photo albums, uploading photos (which I’ll cover in another blog post), commenting. Head over to the Facebook Graph API docs for a full list of actions.
Since we’re developing in Python, we used Facebook’s official Python SDK, which turned out to save a lot of headaches.

Testing

In our Agile manner, tests play an important role. Kay Framework’s test client turned out to have a problem storing cookies (which we’re looking into fixing), so testing properly by doing server requests to Facebook was difficult.
One important story to test is when a user tries to access a non-public page. In that case, the user should be prompted to login with Facebook, then return to the original page.

  1. def test_fb_login_decorator(self):
  2. _create_fb_user(FACEBOOK_UID)
  3. resp = self.client.get('/projects/new/')
  4. # fb user is not logged in and attempts to access this url. redirection expected, hence 302.
  5. self.assertEquals(resp.status_code, 302)
  6. # fb user is logged in and now should be able to access the url.
  7. _facebook_login(self)
  8. resp = self.client.get('/projects/new/')
  9. self.assertEquals(resp.status_code, 200)

Source code

Here’s the link for the source code for the Kay Framework authentication back-end and some usage examples:

http://github.com/tudormunteanu/fb-auth-backend


Category: Python

Discussion

  1. Arun on Sep 20, 2011 - 4:06 said:

    Using the graph api with python using modules available on Google App Engine: http://blog.arunbalan.in/2011/09/20/facebook-canvas-apps-with-python-on-google-app-engine-super-simplified/




Leave a Comment :

(required)


(required)




(required)




(required)






Leave a Comment


Page generated in: 0.18s