Using the OAuth and OAuth-Plugin gems
For quite a while I've been wanting to play with OAuth and now that I've been able to spend some time playing with it I have to say it is awesome. Instead of asking for a user's username and password for a given service (like their GMail or LinkedIn account) you instead have the user log into their account and grant your application access. The benefit is that your application doesn't have to figure out how to securely store a bunch of extra usernames/passwords and the user can turn off access anytime they feel like they need to reclaim their privacy.
In Rails the way to work with OAuth is the OAuth gem and the OAuth-Plugin gem which take almost all the pain out of implementing an OAuth solution. A big thanks to Pelle Braendgaard for a great library.
I won't go into all the details on how to implement the gems in your project. Instead checkout the README for each gem and the articles on Pelle's blog: Developing OAuth clients in Ruby, Major update to Ruby on Rails OAuth Plugin, and Consuming OAuth intelligently in Rails.
Once you have an OAuth solution in place the next step is to do something with the tokens. I figured that it was my problem to figure out how to call the various service's apis using the OAuth token. I spent a fair amount of time trying to figure out how to send the correct headers, sign the values, etc. I turns out that the OAuth gem takes care of this for you so to save you hours of time, once you have your application setup and configured you can do stuff like this:
Google Contacts API:
limit = 10000 user.google.get("http://www.google.com/m8/feeds/contacts/default/full?max-results=#{limit}")
The gem will handle signing the request and adding the needed values to the header.
Pretty cool.
More from jbasdf
- Ruby on Rails i18n with the Rails I18n Textmate bundle
- How New Carpet and Rattlesnake turned me into a Consultant or What the Hell Happened?
- A copy of ApplicationController has been removed from the module tree but is still active! And can’t dup NilClass
- Rails Conf Intro from Chad Fowler and Some Stuff from the Mountain West Ruby Conference
- Mac OSX and the Samsung ML1740 on a network
-
jbasdf
-
dean_genlighten
Justin Ball is a software consultant and entrepreneur with a passion for Ruby. He evolved from a C++ and .Net monkey into a python programmer and finally found Ruby. In the rare moments when he isn't writing code, talking about code or measuring his code productivity in profanity per hour, you can find him on his bike in the mountains or on the roads surrounding Cache Valley. 









