Gmail 的omniauth oauth 令牌无效
我正在尝试获取可以与 gmail_xauth (ruby gem) 一起使用的 oauth 令牌 查看用户的邮件。我首先在谷歌注册了我的应用程序 然后设置设备来请求访问邮件:
config.omniauth :google, 'key', 'secret', :scope => 'https://mail.google.com/mail/feed/atom/'
然后我通过 outh/openid 流程,谷歌提示我 批准访问 Gmail,使用 aa 令牌将我重定向回应用程序 和全能凭证中的秘密我的 Google 帐户列出了我的应用程序 有权访问我的数据。到目前为止,一切都很好。
现在,当我获取这些凭据并尝试将它们与 gmail_xoauth 像这样:
require 'gmail_xoauth'
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs =
nil, verify = false)
imap.authenticate('XOAUTH', '[email protected]',
:consumer_key => 'key,
:consumer_secret => 'secret',
:token => 'omniauth_returned_token',
:token_secret => 'omniauth_returned_secret'
)
我收到错误“Net::IMAP::NoResponseError: 无效凭据 (失败)”。
有趣的是,按照 gmail_xoauth README 生成令牌 对于使用 python 脚本的同一个消费者来说,它确实有效。
I'm trying to get an oauth token I can use with gmail_xauth (ruby gem)
to look at a user's mail. I first registered my app with google and
then set up devise to request access to mail:
config.omniauth :google, 'key', 'secret', :scope => 'https://mail.google.com/mail/feed/atom/'
I then go through the outh/openid flow and google prompts me to
approve access to gmail, redirecting me back to the app with a a token
and secret in the omniuth credentials & my Google account lists my app
as authorized to access my data. So far so good.
Now, when I take those credentials and try to use them with
gmail_xoauth like so:
require 'gmail_xoauth'
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs =
nil, verify = false)
imap.authenticate('XOAUTH', '[email protected]',
:consumer_key => 'key,
:consumer_secret => 'secret',
:token => 'omniauth_returned_token',
:token_secret => 'omniauth_returned_secret'
)
I get an error "Net::IMAP::NoResponseError: Invalid credentials
(Failure)".
Interestingly, following the gmail_xoauth README to generate a token
with an same consumer using a python script it does work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用:
我正在使用 gmail gem,所以连接它看起来像这样:
我正在传递一个身份验证对象,但您将从 env 变量 env["omniauth.auth ”]。我使用匿名/匿名作为密钥/秘密,因为我还没有向谷歌注册我的域名,但我相信你可以这里。它仍然适用于匿名/匿名,但谷歌只会警告用户。
This works for me:
I'm using the gmail gem, so to connect it looks like this:
I'm passing an authentication object in, but you'll be getting it from the env variable env["omniauth.auth"]. I'm using anonymous/anonymous for the key/secret since I haven't registered my domain with google, but I believe you can here. It'll still work with anonymous/anonymous, but Google will just warn the user.
Google 的 OAuth1 协议现已弃用,许多 gem 尚未更新以使用其 OAuth2 协议。以下是使用 OAuth2 协议从 Google 获取电子邮件的工作示例。此示例使用
mail
、gmail_xoauth
,omniauth
和omniauth-google-oauth2
宝石。您还需要在 Google 的 API 控制台中注册您的应用才能获取 API 令牌。
Google's OAuth1 protocol is now deprecated and many gems have not yet updated to use their OAuth2 protocol. Here is a working example of fetching email from Google using their OAuth2 protocol. This example uses the
mail
,gmail_xoauth
,omniauth
, andomniauth-google-oauth2
gems.You will also need to register your app in Google's API console in order to get your API tokens.