gmailgem / gmail

A Rubyesque interface to Gmail, with all the tools you'll need.
Other
397 stars 119 forks source link

Connect using xoauth #165

Closed maartenvanrijn closed 4 years ago

maartenvanrijn commented 9 years ago

Hey all,

I have set up oauth2. I can connect my gmail account to it / authenticate with my google account. When using the xoauth gem I can connect using imap.authenticate('XOAUTH2', email, access_token) However, I cannot connect using gmail = Gmail.connect(:xoauth, email, access_token)

I don't have a 'secret', 'consumer_key', 'consumer_secret' nor do I need any when connecting using the imap.authenticate method.

What am I not seeing / doing wrong?

johnnyshields commented 9 years ago

I don't use xoauth. @gmailgem/owners can anybody assist?

PranayPant commented 9 years ago

Hi, I am having trouble using this gem with oauth2 set up. I am using Ruby on Rails with Rails 4.2.1 My Gemfile looks like this: ... gem 'omniauth-google-oauth2' gem 'oauth2' gem 'google-api-client' gem 'gmail', :require => true, git: "https://github.com/gmailgem/gmail.git" ... In a controller, I do ... gmail = Gmail.connect(:xoauth2, @user.email.to_s, :oauth2_token => @user.token.to_s) ... I then proceed to do 'gmail.inbox.count', where I get the following error:

Net::IMAP::BadResponseError. Unknown command dh9mb210919324pdb

Extracted source (around line #13): 12 gmail = Gmail.connect(:xoauth2, @user.email.to_s, :oauth2_token => @user.token.to_s) 13 @test = gmail.inbox.count 14 end 15 end

It says you guys added support for xoauth2, but I'm not sure how to use it with the Gmail.connect(...) Is what I'm trying to do even possible right now?

Thanks,

PranayPant commented 9 years ago

Try using gmail = Gmail.connect(:xoauth2, email, token => "my_access_token").

SudhagarS commented 9 years ago

@PranayPant Hey, did this work? I am facing the same issue. Gmail object I get is disconnected, <Gmail::Client0x7fe9b1cb4ec0 (sudhagar@gmail.com) disconnected>

I am using, gmail = Gmail.connect( :xoauth2, auth[:info][:email], :token => auth[:credentials][:token], )

SudhagarS commented 9 years ago

Looking at the source code, there is no need for hash param there. So just Gmail.connect(:xoauth2, email, oauth_token) would work.

PranayPant commented 9 years ago

I 'm using gem google-api-client instead of this. I found it better (and usable - couldn't figure out OAuth 2.0 connection with other gems).

ghost commented 9 years ago

Using Gmail.connect(:xoauth2, email, oauth_token) I'm getting disconnected object as well.

SudhagarS commented 9 years ago

@johnnyshields Hi, any idea why this is failing?

ghost commented 9 years ago

@SudhagarS it seems that the main gem gmail_xoauth might be the issue. I wasn't able to get it to work with that as well. The solution for me was to use google-api-client and make sure correct APIs are enabled in Google API console.

SudhagarS commented 9 years ago

@gonchs Thanks for the info. I really like the interface in this library and google libraries seems over engineered to me.

robins35 commented 9 years ago

Still no solution here? This gem is essentially unusable until somebody fixes this. Nobody is going to use an app that makes you set access for less secure apps to true.

johnnyshields commented 9 years ago

@robins35 we could use your help to debug this. I would recommend to start by determining whether the problem lies in this library or in https://github.com/nfo/gmail_xoauth, which is a dependency of this library.

dodontommy commented 8 years ago

I can't get auth to work either with OAuth, essentially rendering this gem useless.

nhodges commented 8 years ago

What is the error you get when you use the verbose / exception-throwing connect! method?

sthoward commented 7 years ago

Any update on this? I'm also getting the <Gmail::Client{{numbers}} ({{email}}) disconnected>

cstavitsky commented 7 years ago

I'm also still getting the <Gmail::Client{{numbers}} ({{email}}) disconnected>.

PranayPant commented 7 years ago

Man this issue has been there for a loooooooong time...time to switch platforms you guys!

johnnyshields commented 4 years ago

As of version 0.7.0 (Aug 19, 2018) this gem is officially deprecated and will no longer be maintained. Please instead use Google's official Gmail API Ruby Client, which uses the Gmail API rather than IMAP and has significantly better performance and reliability.