How do I connect to Gmail's IMAP server using oauth in Rails3?
Asked Answered
L

2

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/

Ludwick answered 21/9, 2010 at 18:11 Comment(4)
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: github.com/pelle/oauth.Balancer
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 gmailBalancer
One more thing, an SMTP/IMAP (sending/receiving) example would be immensely appreciated.Balancer
omniauth might also be an appropriate gemBalancer
G
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!

Graveyard answered 6/1, 2011 at 2:39 Comment(2)
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.Ludwick
What issue did you have with OmniAuth?Graveyard
P
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/

Phyto answered 30/11, 2010 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.