如何使用omniauth对服务进行经过身份验证的调用?
我已使用 OmniAuth 从服务收到令牌/秘密,并可以为用户存储它,但我不知道如何实际使用这些来调用服务。
我见过的最接近这个问题的是这里但是他的方式解决了感觉不对的地方。我觉得如果您知道自己在做什么,OmniAuth 可能会为您完成这一切。
Netflix 有一个相当复杂的身份验证过程,所以我希望通过使用 OmniAuth 将我从这一切中抽象出来。
假设我有一个用户的令牌和秘密,如何使用它们来调用像 Netflix 这样的服务?
非常感谢:)
I've received a token / secret from a service using OmniAuth and can store it for users, but I'm stuck as to how to actually use these to call a service.
The closest thing I've seen to this question is here but the way he's solved that there doesn't feel right. I feel like OmniAuth likely does this all for you if you know what you're doing.
Netflix has a pretty involved auth process, so I was hoping to skirt all of this by using OmniAuth to abstract me from all of this.
Given that I have a token and secret for a user, how to use these in calling a service like Netflix?
Many thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿,我是 OmniAuth gem 的作者。 OmniAuth 用于身份验证过程。对于像 Netflix 这样的 OAuth 提供商,这意味着将请求令牌交换为访问令牌,然后使用该访问令牌从 API 中提取用户信息。这些一次性调用是专门为每个提供商设计的,并不意味着成为给定提供商的通用 API 客户端。
您可以使用 OmniAuth 来获取凭据,然后使用站点本身的另一个特定库(例如
ruby-netflix
或其他任何内容,我不确定最好的办法是什么)打电话。您可以通过访问env['omniauth.auth']['credentials']
检索在身份验证舞蹈中获得的访问令牌和密钥,然后使用它们来初始化 API 客户端。您还可以直接使用 OAuth 库来进行这些调用,但我强烈建议仅使用现有的库,它会更快、更容易。这一切有意义吗?
Hey, I'm the author of the OmniAuth gem. OmniAuth is meant to be used for the authentication process. In the case of OAuth providers like Netflix, this means exchanging a request token for an access token which is then used to pull user information from the API. These one-off calls are specifically designed for each provider and are not meant to be a generic API client for the given provider.
What you can do it use OmniAuth to obtain the credentials and then use another specific library for the site itself (such as
ruby-netflix
or anything else, I'm not sure what the best one is) to make calls. You can retrieve the access token and secret that is obtained in the authentication dance by accessingenv['omniauth.auth']['credentials']
, then use those to initialize the API client.You can also use the OAuth library directly to make these calls, but I would strongly recommend just using an existing library, it will be much faster and easier. Does all of that make sense?
OmniAuth 是关于身份验证的;您可能应该查看另一个 gem 来对服务进行实际调用。例如,对于 Facebook,我使用 OAuth2 gem 和代码,如下所示:
请注意,流行服务(例如 Facebook 和 Twitter)有 gem,它们可以管理幕后事务,例如创建令牌、管理 URL 等。 Netflix,您可以检查以下内容:
另请记住,OmniAuth 只是将服务数据返回给您;您可以自由地存储它并按照自己的方式使用它(Devise 有自己的 OmniAuth 模式,如果您尝试越界,您可能会遇到这种模式)。您链接的另一个问题对我来说看起来并不太牵强。
OmniAuth is all about authentication; you should probably look at another gem for making actual calls to the service. E.g., for Facebook, I use the OAuth2 gem and code like the following:
Note that there are gems for popular services, like Facebook and Twitter, that can manage the behind-the-scenes things like creating tokens, managing URLs, etc. For Netflix, you might check the following:
Also keep in mind that OmniAuth just returns the service data to you; you're free to store it and use it how you will (Devise has it's own pattern for OmniAuth that you might butt heads with if you try to go outside the lines). The other question you linked doesn't look too far fetched to me.