【问题标题】:Magento customer authentication via API通过 API 进行 Magento 客户身份验证
【发布时间】:2013-04-16 07:59:50
【问题描述】:

我正在将 Magento 与第 3 方 Java Web 应用程序一起使用。 我的应用程序通过 Magento SOAP API V2 “连接”到 Magento。

如何通过 api 从我的 Java 应用程序(Magento 之外)执行客户身份验证?

任何帮助将不胜感激。

【问题讨论】:

    标签: java php api magento soap


    【解决方案1】:

    我想出了一个关于如何通过 SOAP API 登录客户的解决方案,我将在此处发布,以便对其他人有所帮助。这是我为使其工作所做的工作:

    1. 我在 Magento 中创建了一个自定义模块,使用自定义方法登录客户并重新调整服务器端设置的 sessionID

      Mage::app()->setCurrentStore($website);
      // Init a Magento session. This is super ultra important
      Mage::getSingleton('core/session'); 
      
      // $customer Mage_Customer_Model_Customer
      // We get an instance of the customer model for the actual website
      $customer = Mage::getModel('customer/customer')
          ->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
      
      // Load the client with the appropriate email
      $customer->loadByEmail($email);
      
      // Get a customer session
      $session = Mage::getSingleton('customer/session');
      
      $session->loginById($customer->getId());
        if ($session->isLoggedIn()) {
          return $session->getSessionId();
      } else {
           return null;
      }
      
    2. 我创建了一个Magento Custom Api,所以我可以通过 SOAP 调用我的登录方法。

    3. 从我的 JAVA 应用程序调用登录方法,获取 sessionId,然后根据收到的 sessionId 在浏览器上设置 cookie。 http://yourmagentohost/setCookies.php?sessionId=your_session_id

    setCookies.php 里面你有:setcookie("frontend", $_GET["sessionId"] , time()+3600);

    就是这样,现在您有一个登录的客户。

    【讨论】:

      【解决方案2】:

      如何从我的 Java 应用程序执行客户身份验证 (在 Magento 之外)通过 api? SOAP API V2

      澄清: API 用户(至少是 Soap)和客户是两种用户类型。如果您有一个预先存在的用户列表,并且正在寻找他们是否作为用户在 Magento 内部存在,您可以检索电子邮件帐户及其相关属性和相应的密码哈希(CE:md5:salt,或 CE/EE:sha :salt) 全部通过 SOAP。如果您希望进行比较操作,则需要对您的密码实施相同的散列以进行 1:1 比较。如果您希望您的应用程序使用 SOAP 直接执行操作,我会确保有一个抽象层,因为您的应用程序可能会被用于恶意针对其他用户 ID,这一切都取决于 Magento 管理员中设置的 SOAP 角色和 ACL . 继续……

      V2:您必须切换到 Java,例如:PHP。

      $username 'yourUsername';
      
      $password = 'yourApiKeyPlainText';
      
      $proxy = new SoapClient('https://www.yourdomain.com/magento/api/v2_soap?wsdl=1');
      
      $sessionId = $proxy->login($username, $password);
      
      //Get a Full customer List from Magento
      $customerList = $proxy->customerCustomerList($sessionId);
      //get back a list    
      
      //Target a user from your List, Compare Details against your App
      $customerInfo = $proxy->customerCustomerInfo($sessionId, '2'); //Customer Id
      

      可能会涉及到远程操作,例如 Checkout。问题仍然存在,您希望在您的应用旁边或代表用户做什么?

      参考资料: http://www.magentocommerce.com/api/soap/customer/customer.list.html http://www.magentocommerce.com/api/soap/customer/customer.info.html

      干杯,

      【讨论】:

        【解决方案3】:

        您的代码示例不使用 SOAP。 Magento SOAP 访问实际上如下所示:

        
            $client = new SoapClient('http://magentohost/soap/api/?wsdl');
        
            // If somestuff requires api authentification,
            // then get a session token
            $session = $client->login('apiUser', 'apiKey');
        

        查看 API 文档:http://www.magentocommerce.com/api/soap/introduction.html

        【讨论】:

        • 正如您的代码注释中所写,它执行 api 身份验证,而不是 客户身份验证
        • 根据文档,没有调用创建客户会话或设置适当的cookies,以便客户在之后访问商店时登录。
        猜你喜欢
        • 1970-01-01
        • 2016-04-16
        • 2019-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-13
        • 2015-02-26
        相关资源
        最近更新 更多