首页 > 解决方案 > 如何在 Ruby 中验证 oauth、Magento 2.0 SOAP

问题描述

使用 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 肥皂集成并给我一些指示。

标签: rubymagento2savon

解决方案


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

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


推荐阅读