12

I found the gmail_xoauth gem, which does most of what I need, but I also need to generate the oauth tokens (consumer_key and consumer_secret) from inside Rails3.

I am trying to integrate Gmail's oauth integration into my site and hence cannot use the python script that the above gem refers to. I would like my site to take the user to the authentication page and extract the consumer_key/secret tokens.

I am new to OAuth, so maybe there's something obvious that I am missing.

UPDATE: I solved the above, and have written a blog post with the details (since its too big to fit here). http://blog.asif.in/blog/2012/03/03/google-oauth-and-rails/

Asif Sheikh
  • 1,065
  • 2
  • 8
  • 18
  • 1
    For the bounty-hunters: the answer to this question will probally be fairly involved, so I will accept a link to your blog post, if it's complete. I'm pretty sure any correct answer will employ a combination of the plugin @sheikh mentions and: https://github.com/pelle/oauth. – SooDesuNe Nov 29 '10 at 23:06
  • This means the answer will need to address 1) getting consumer access permission from the provider 2) storing any appropriate information for the user 3) making the consumer request to gmail – SooDesuNe Nov 29 '10 at 23:07
  • One more thing, an SMTP/IMAP (sending/receiving) example would be immensely appreciated. – SooDesuNe Nov 29 '10 at 23:22
  • 1
    omniauth might also be an appropriate gem – SooDesuNe Nov 30 '10 at 01:51

2 Answers2

2

You may want to check out OmniAuth. It's a gem that encapsulates/abstracts a lot of the underlying protocol work that must be done for OAuth, as well as other authentication/authorization protocols like OpenID and LDAP. I'm not well versed on Google's API for sending/receiving email, but authenticating is the first step.

The OmniAuth wiki has a very good tutorial on using it with OpenID and Google Apps, although this may not be quite what you're looking for when it comes to IMAP. You may need to write your own provider for OmniAuth (a good tutorial describing this is available). Google also provides a reference site for authenticating/authorizing via IMAP and OAuth. The most relevant part of that to you would most likely be the page detailing the protocol.

Hope that helps!

  • I tried using OmniAuth but it didn't work well for me. I managed to get it working by converting Google's example python code to Ruby, and adding the appropriate controllers. Since it's fairly involved, I will write up a blog post soon with the details. – Asif Sheikh Jan 16 '11 at 17:43
  • 1
    What issue did you have with OmniAuth? – Anthony Burns Jan 19 '11 at 00:10
0

I'm not going to write the full code for you, but do you know PHP? You could have a look at the way this example works:

http://googlecodesamples.com/docs/php/Docs.php

...then make something similar in Ruby.

This is a Google Code Sample from the following site:

http://googlecodesamples.com/

Geoff
  • 9,470
  • 13
  • 52
  • 67