Send Ad Free SMS in India

Authentication using Google Accounts for your Rails App

September 28, 2009 | In: API, Rails, Web 2.0

The methodology is very simple.

  1. Redirect the user to grant access to your app for a particular Google service.
  2. Once access is granted, use the authentication token to retrieve information related to the user.

I demonstrate this with a very simple & idiotic Sinatra app which actually does nothing intelligent – apart from just outputting first 10 contacts from the user’s address book.

  1. require ‘rubygems’
  2. require ‘sinatra’
  3. require "gdata"
  4.  
  5. client = GData::Client::Contacts.new
  6.  
  7. get "/" do
  8.   next_url = ‘http://127.0.0.1:4567/app’
  9.   secure = false
  10.   session = true
  11.   authsub_link = client.authsub_url(next_url, secure, session, nil)
  12.   redirect(authsub_link)
  13. end
  14.  
  15. get ‘/app’ do
  16.   pp request.env
  17.   client.authsub_token = request.env["rack.request.query_hash"]["token"]
  18.   client.authsub_token = client.auth_handler.upgrade()
  19.   contacts = client.get("http://www.google.com/m8/feeds/contacts/default/full?max-results=5").to_xml
  20.   puts contacts
  21. end

More information about using GData is available at http://code.google.com/apis/gdata/articles/gdata_on_rails.html

Example scenarios this can be used?

  • Allowing people to login into your app with their existing google account.
  • Accessing user data with user’s permission
  • Signing up for your app using Google account information

Happy Hacking!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to MySpace Post to Reddit Post to StumbleUpon

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.



View Comments to Authentication using Google Accounts for your Rails App

Avatar

Tweets that mention Dare to Dream? » Blog Archive » Authentication using Google Accounts for your Rails App -- Topsy.com

September 28th, 2009 at 1:24 am

[...] This post was mentioned on Twitter by makuchaku. makuchaku said: Just blogged – Authentication using Google Accounts for your Rails App http://bit.ly/K4TAn [...]

Comment Form

blog comments powered by Disqus