【问题标题】:Disable WooCommerce API authentication for Custom endpoint禁用自定义端点的 WooCommerce API 身份验证
【发布时间】:2018-07-27 16:01:52
【问题描述】:

我创建了一个自定义 WooCommerce API 端点(在自定义 WP 插件中),用于在 WooCommerce 中创建新订单。我通常使用带有消费者密钥和消费者秘密的 HTTPS 和基本身份验证。

此客户 API 旨在供其他平台访问,该平台无法在请求标头中输入使用者密钥和机密。所以我想只为这个插件禁用 WooCommerce 身份验证。我将通过比较密钥使用原始请求中的字段进行身份验证。

有人知道怎么做吗?

【问题讨论】:

    标签: wordpress restful-authentication woocommerce-rest-api


    【解决方案1】:

    我找到了解决办法:

    // To disable authentication, hook into this filter at a later priority and return a valid WP_User
    
        add_filter( 'woocommerce_api_check_authentication', array( $this, 'authenticate' ), 0 );
    

    【讨论】:

      【解决方案2】:

      如果要禁用 v3 的身份验证,请禁用 plugins/woocommerce/incoudes/api/legacy/v3/class-wc-api-authentication.php 中的第 152、153 行

      //$this->check_oauth_signature( $keys, $params );
      //$this->check_oauth_timestamp_and_nonce( $keys, $params['oauth_timestamp'], $params['oauth_nonce'] );
      

      【讨论】:

        【解决方案3】:

        在文件 woocommerce/includes/class-wc-rest-authentication.php 中注释以下行

            if ( !hash_equals( $signature, $consumer_signature ) ) { @codingStandardsIgnoreLine
            return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid signature - provided signature does not matchh.', 'woocommerce' ), array( 'status' => 401 ) );
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-06-18
          • 2019-03-17
          • 2020-09-19
          • 2016-03-15
          • 1970-01-01
          • 1970-01-01
          • 2019-03-31
          • 1970-01-01
          相关资源
          最近更新 更多