0

I am working on oauth authentication for my app and am planning to use Oauth2. Can someone tell if Gmail supports fetching Inbox by the Oauth2 access-token.I saw it is possible to do this by the Oauth1 token but I found that Oauth1 support is deprecated by Google now.

code4fun
  • 2,661
  • 9
  • 25
  • 39

2 Answers2

2

Nope, just OAuth 1.0 right now.

Steve Bazyl
  • 11,002
  • 3
  • 21
  • 24
1

Here is a working, Ruby example of fetching email from Google using their XOAUTH2 protocol:

imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.authenticate('XOAUTH2', 'example@gmail.com', 'oauth2_access_token_goes_here')
imap.select('INBOX')
imap.search(['ALL']).each do |message_id|

    msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
    mail = Mail.read_from_string msg

    puts mail.subject
    puts mail.text_part.body.to_s
    puts mail.html_part.body.to_s

end

Note: This example uses the ruby mail gem and the gmail_xoauth gem, so you will need that installed for this code sample to work.

Also, retrieving the OAuth2 access token is not shown in this example. Here's an example using the ruby OmniAuth gem.

Community
  • 1
  • 1
Andrew
  • 227,796
  • 193
  • 515
  • 708