是否可以使用 OmniAuth 获取 Gmail oauth 或 xauth 令牌?
我想从 GMail 获取 oauth 或 xauth 令牌以与 gmail-oauth 一起使用。我正在考虑使用 OmniAuth 但它似乎还不支持 GMail,这意味着库存 OmniAuth 是不可能的。这是正确的吗?我错过了什么吗?
I want to get oauth or xauth tokens from GMail to use with gmail-oauth. I'm thinking of using OmniAuth but it seems not to support GMail yet, which means that with stock OmniAuth is impossible. Is that correct? Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Omniauth 支持 OAuth 和 OAuth2,这将两者允许您验证 Google 帐户。
以下是您可以通过omniauth 使用的所有策略:
https://github.com/intridea/omniauth/wiki/List-of-Strategies
以下是两个 google OAuth gem:
根据第一个 gem 的文档:
添加config/initializers/omniauth.rb 中 Rails 应用程序的中间件:
这是此外设置主要omniauth gem。
Omniauth has support for both OAuth and OAuth2, which will both allow you to authenticate a google account.
Here are all of the strategies you can use via omniauth:
https://github.com/intridea/omniauth/wiki/List-of-Strategies
Here are the two google OAuth gems:
As per the documentation of the first gem:
Add the middleware to a Rails app in config/initializers/omniauth.rb:
This is done in addition to setting up the main omniauth gem.
我和你一样,在使用现有的 gems 与 OAuth2 和 Gmail 时遇到了麻烦,因为 Google 的 OAuth1 协议现已弃用,并且许多 gems 尚未更新以使用其 OAuth2 协议。我终于能够直接使用 Net::IMAP 让它工作了。
以下是使用 OAuth2 协议从 Google 获取电子邮件的工作示例。此示例使用
mail
、gmail_xoauth
,omniauth
和omniauth-google-oauth2
宝石。您还需要在 Google 的 API 控制台中注册您的应用才能获取 API 令牌。
I had trouble, like you, using existing gems with OAuth2 and Gmail since Google's OAuth1 protocol is now deprecated and many gems have not yet updated to use their OAuth2 protocol. I was finally able to get it to work using
Net::IMAP
directly.Here is a working example of fetching email from Google using the 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.