Par*_*son 8 ruby gmail oauth devise omniauth
我正在尝试使用gmail_xauth(ruby gem)来查看用户的邮件.我首先使用谷歌注册我的应用程序,然后设置设计请求访问邮件:
config.omniauth :google, 'key', 'secret', :scope => 'https://mail.google.com/mail/feed/atom/'
Run Code Online (Sandbox Code Playgroud)
然后我浏览了outh/openid流程,谷歌提示我批准访问gmail,将我重新定向到带有令牌的应用程序和全知凭证中的秘密,我的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'
)
Run Code Online (Sandbox Code Playgroud)
我收到错误"Net :: IMAP :: NoResponseError:无效凭据(失败)".
有趣的是,遵循gmail_xoauth README使用python脚本生成具有相同使用者的令牌,它确实有效.
这对我有用:
config.omniauth :google, 'anonymous', 'anonymous', :scope => 'https://mail.google.com/'
Run Code Online (Sandbox Code Playgroud)
我正在使用gmail gem,所以连接它看起来像这样:
gmail = Gmail.connect(:xoauth, auth.uid,
:token => auth.token,
:secret => auth.secret,
:consumer_key => 'anonymous',
:consumer_secret => 'anonymous'
)
Run Code Online (Sandbox Code Playgroud)
我正在传递一个身份验证对象,但你将从env变量env ["omniauth.auth"]中获取它.我使用匿名/匿名密钥/秘密,因为我没有在谷歌注册我的域名,但我相信你可以在这里.它仍然可以与匿名/匿名合作,但谷歌只会警告用户.