我正在尝试获取可以与gmail_xauth(ruby gem)一起使用的oauth token
查看用户的邮件。我首先在Google注册了我的应用,
然后设置装置以请求访问邮件:
config.omniauth :google, 'key', 'secret', :scope => 'https://mail.google.com/mail/feed/atom/'
然后,我通过outh/openid流程,谷歌提示我
批准访问gmail,并使用 token 将我重定向回该应用
全方位凭证中的 secret 和我的Google帐户列出了我的应用
被授权访问我的数据。到现在为止还挺好。
现在,当我获取这些凭据并尝试将其与
gmail_xoauth像这样:
require 'gmail_xoauth'
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs =
nil, verify = false)
imap.authenticate('XOAUTH', '...@gmail.com',
:consumer_key => 'key,
:consumer_secret => 'secret',
:token => 'omniauth_returned_token',
:token_secret => 'omniauth_returned_secret'
)
我收到一个错误“Net::IMAP::NoResponseError:无效的凭据
(失败)”。
有趣的是,按照gmail_xoauth自述文件生成 token
与使用python脚本的同一个使用者一起使用确实有效。
最佳答案
这对我有用:
config.omniauth :google, 'anonymous', 'anonymous', :scope => 'https://mail.google.com/'
我正在使用gmail gem,因此连接起来看起来像这样:
gmail = Gmail.connect(:xoauth, auth.uid,
:token => auth.token,
:secret => auth.secret,
:consumer_key => 'anonymous',
:consumer_secret => 'anonymous'
)
我传入了一个身份验证对象,但是您将从env变量 env [“omniauth.auth”] 中获得它。由于我尚未在google上注册我的域,因此我使用匿名/匿名作为 key / secret ,但我相信您可以here。它仍然可以与匿名/匿名一起使用,但是Google会警告用户。
关于ruby - gmail的omniauth oauth token 无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5615751/