如何在Ruby中验证oauth,Magento 2.0 SOAP

时间:2018-08-17 13:19:41

标签: ruby magento2 savon

使用oauth凭据向Magento 2 SOAP进行身份验证时出现问题。

对于magento 1.9版本,这非常简单:

client = Savon.client(
  wsdl: "https://example.com/api/soap/?wsdl=1",
  log: true,
  pretty_print_xml: true
)
session_id = client.call(:login, message: { username: "username", apiKey: "key" })body[:login_response][:login_return]
client.call(:call, message:{resource_path: 'catalog_product.list', session_id: session_id}).body

按预期工作。使用oauth会变得更加复杂。 我尝试了各种不同的方法,例如:

client = Savon.client(
    wsdl: "http://example.com/index.php/soap/default?wsdl_list=1",
    soap_header: { 'Authorization:' => "Basic xxxx"},
    pretty_print_xml: true
)

client.call(:call, message:{resource_path: 'catalogProductAttributeGroupRepositoryV1'}).body

希望有人已经完成了oauth-magento 2 soap的集成,并给了我一些建议。

1 个答案:

答案 0 :(得分:0)

您需要从admin创建一个新的集成以获取身份验证密钥。这些链接将是有用的资源:

https://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-oauth.html https://gist.github.com/rafaelstz/ecab668b80fece4d9acdb9c5358b3173