Ruby on Rails:如何使用 OAuth2::AccessToken.post? [英] Ruby on Rails: how to use OAuth2::AccessToken.post?
问题描述
OAuth2::AccessToken.post() 方法在文档中是这样指定的:
OAuth2::AccessToken.post() method is specified like this in the documentation:
(Object) post(path, opts = {}, &block)
(Object) post(path, opts = {}, &block)
我试图传递一些参数,但似乎我做错了:
I'm trying to pass some arguments, but seems that I*m doing it wrong:
response = token.post('/oauth/create.js', {:title => "title", :description => "desc"})
参数永远不会到达方法,值总是为零.那么,使用带有参数的 post 方法的正确方法是什么?那 &block 是什么?
The parameters are never reaching the method, values are always nil. So, what is the correct way of using the post method with arguments? And what is that &block?
我也收到警告:无法验证 CSRF 令牌的真实性.这也可能是导致问题的原因.情况是我从应用程序外部使用 OAuth api.OAuth 2 是通过 Doorkeeper gem 实现的.
I'm also getting WARNING: Can't verify CSRF token authenticity. This might be contributing to the problem as well. The case is that I'm using OAuth api from the outside of the app. OAuth 2 is implemented via Doorkeeper gem.
更新:在我定义范围后,CSRF 警告现在消失了.此外,我通过提供 url 的一部分来设法使用这个 post() 方法和参数:?title=test&...".仍然很高兴知道如何按照文档使用此方法.
Update: The CSRF warning is gone now after I defined scopes. Also I manage to use this post() method with arguments by providing the as part of the url: "?title=test&...". Still would be nice to know how to use this method as documented.
推荐答案
POST 或 PUT 中的正文通过 options body 参数访问.没有这方面的文档.不得不查看 oauth 客户端代码本身才能发现这一点:
The body in a POST or PUT is accessed via the options body param. No documentation on this. Had to look in the oauth client code itself to discover this:
你的例子,正确的身体是:
Your example, with correct body would be:
response = token.post('/oauth/create.js', {body: {:title => "title", :description => "desc"}})
这篇关于Ruby on Rails:如何使用 OAuth2::AccessToken.post?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!