Magento OAuth和REST API的麻烦 [英] Magento oauth and REST api trouble

查看:109
本文介绍了Magento OAuth和REST API的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的ruby on rails应用程序集成到magento中,我已经提出了最初的请求,获得了授权,我相信我会获得最终的令牌,但是我不确定.这是我的回应:

I’m trying to integrate my ruby on rails app to magento, and I got so far as to make the initial request, get authorized, and I believe I’m getting the final token, but I can’t be sure. Here is what I have in my response:

(这里有很多东西,所以请跳过我提取导入位的地方)

(There’s a lot of stuff here, so skip ahead where I pluck out the import bits)

 .....
 "credentials"=>
  {"token"=>"r8apb2rcgci9ry5hugcuiqlnwdi0evc1",
   "secret"=>"8pnyogb4048toujt5rjoq26tqh50vkv5"},
 "extra"=>
  {"access_token"=>
    #<OAuth::AccessToken:0x007fdd59893468
     @consumer=
      #<OAuth::Consumer:0x007fdd5995f928
       @http=#<Net::HTTP mymagentocart.dev:443 open=false>,
       @http_method=:post,
       @key="ttuj6ok0ioziv7bcfwi8wprzqe6o4x1e",
       @options=
        {:signature_method=>"HMAC-SHA1",
         :request_token_path=>"/oauth/initiate",
         :authorize_path=>"/admin/oauth_authorize",
         :access_token_path=>"/oauth/token",
         :proxy=>nil,
         :scheme=>:header,
         :http_method=>:post,
         :oauth_version=>"1.0",
         :site=>"https://mymagentocart.dev"},
       @secret="b0maut2ftkg2wb3nm24t263720n7kxqa">,
     @params=
      {:oauth_token=>"r8apb2rcgci9ry5hugcuiqlnwdi0evc1",
       "oauth_token"=>"r8apb2rcgci9ry5hugcuiqlnwdi0evc1",
       :oauth_token_secret=>"8pnyogb4048toujt5rjoq26tqh50vkv5",
       "oauth_token_secret"=>"8pnyogb4048toujt5rjoq26tqh50vkv5"},
     @secret="8pnyogb4048toujt5rjoq26tqh50vkv5",
     @token="r8apb2rcgci9ry5hugcuiqlnwdi0evc1">},
 "oauth_token"=>"jj2dbrea7dimxwc0twibyoikxjazvs6y",
 "oauth_verifier"=>"83idqmtmb76fe5axad1rf7lhfa3wqxki"
.....

我在访问令牌中看到了我的密钥和秘密:

I see in the access token, my key and secret:

@key="ttuj6ok0ioziv7bcfwi8wprzqe6o4x1e" 
@secret="b0maut2ftkg2wb3nm24t263720n7kxqa"

这是我在管理员中创建REST使用者时magento给我的.

This is what magento gave me when I created a REST consumer in the admin.

然后有很多重复的令牌和秘密,但是它们都是一样的,并且都属于凭据"标签:

Then there’s a bunch of repeated token and secrets, but they’re all the same and fall under the "credentials" label:

"token"=>"r8apb2rcgci9ry5hugcuiqlnwdi0evc1" 
"secret"=>"8pnyogb4048toujt5rjoq26tqh50vkv5"

最后,还有oauth_token和oauth_verifier:

And finally, there’s the oauth_token and oauth_verifier:

"oauth_token"=>"jj2dbrea7dimxwc0twibyoikxjazvs6y" 
"oauth_verifier"=>"83idqmtmb76fe5axad1rf7lhfa3wqxki"

所以这是我的问题...

So here’s my problem…

我其中哪些需要在以后的请求中通过以立即进行身份验证,而无需重新生成令牌?

Which of these do I need to pass with future requests to authenticate straight away without needing to regenerate a token?

当前在我的应用中,每次我提出请求时,它都会不断将我发送回magento的用户确认屏幕进行授权.

In my app currently, each time I make a request, it keeps sending me back to the user confirmation screen in magento to authorize.

此外,我该如何请求获取我的magento用户ID,名称等…,以便我可以使用此信息在Rails应用中生成用户?

Also, how can I make a request to get my magento user id, name, etc… so I can generate a user in rails app using this info?

谢谢!

推荐答案

您拥有访问令牌对象,因此您应该可以执行以下操作:

You have the access token object so you should be able to do something like this:

auth_hash["extra"]["access_token"].get("/api/rest/products")

如果您要创建一个新的访问令牌对象,则可以使用我从示例中提取的密钥和令牌执行以下操作:

If you want to create a new access token object you can do the following with the keys and tokens I pulled from your example:

@consumer=OAuth::Consumer.new("ttuj6ok0ioziv7bcfwi8wprzqe6o4x1e", "b0maut2ftkg2wb3nm24t263720n7kxqa", {:site => "https://mymagentocart.dev"})
@access_token = OAuth::AccessToken.new(@consumer, "r8apb2rcgci9ry5hugcuiqlnwdi0evc1", "8pnyogb4048toujt5rjoq26tqh50vkv5")
@access_token.get("/api/rest/products")

请参阅此页上的使用永久访问令牌": http://code.google.com/p/oauth-plugin/wiki/AccessToken

See "Using a long living Access Token" on this page: http://code.google.com/p/oauth-plugin/wiki/AccessToken

这篇关于Magento OAuth和REST API的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆