Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/

like image 894
Asif Sheikh Avatar asked Sep 21 '10 18:09

Asif Sheikh


People also ask

Does Gmail support oauth2?

Gmail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data. You can also use Google Sign-in to provide a "sign-in with Google" authentication method for your app.

What is XOAUTH2?

What is XOAUTH2? XOAUTH2 is an authentication method used as the default for logging into IMAP mailboxes in GMail, among others. According to this post, XOAUTH2 includes the OAuth 2.0 standard and additional non-standard SASL binding for OAuth. This post covers authentication using XOAuth2 for IMAP and SMTP mailboxes.


1 Answers

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!

like image 162
Anthony Burns Avatar answered Oct 21 '22 10:10

Anthony Burns