douhuan1950 2018-10-23 08:21
浏览 65

Woocommerce和WSO2 Intregration身份验证

We are using a Woocommerce Webhook to send a JSON request to a client who is using WSO2, but if they switch on authentication I get 401 error.

I have tried setting the consumer key and secret with wp_remote_post() and used the username and password and add it in the header for the request. These are more less the same thing but this is what I tried:

token = array( 'key' => 'MY_KEY','secret' => 'MY_SECRET',  'username' => 'MY_USERNAME', 'password' =>  'MY_PASSWORD',   'default'); 
$response = wp_remote_post('URL', array(
    'headers' => array(
        'username' => 'MY_USERNAME',
        'password' => 'MY_PASWORD',
        'Authorization' => 'basic ' . $token,
        'key' => 'CONSUMER KEY',
        'secret' => 'SECRET',  
        'username' => 'USERNAME', 
        'password' =>  'PASSWORD',   
        'www-authenticate' => array( 'key' => 'CONSUMER KEY','secret' => 'CONSUMER KEY',  'username' => 'USERNAME', 'password' =>  'PASSWORD',   'default'),));

$basicauth = 'Basic ' . base64_encode( 'USERNAME' . ':' . 'PASSWORD' );

$headers = array( 
        'Authorization' => $basicauth,
        'Content-type' => 'application/json',
        'Content-length' => $contentlen
        );

$pload = array(
    'method' => 'POST',
    'timeout' => 30,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking' => true,
    'headers' => $headers,
    'body' => $bdy,
    'cookies' => array()
    );

$response = wp_remote_post('URL', $pload);

This is the response I receive:

        [Response] => Array
            (
                [Code] => 401
                [Message] => Unauthorized
                [Headers] => Requests_Utility_CaseInsensitiveDictionary Object
                    (
                        [data:protected] => Array
                            (
                                [date] => Tue, 23 Oct 2018 06:43:03 GMT
                                [server] => server
                                [accept] => */*
                                [access-control-allow-origin] => *
                                [access-control-allow-methods] => POST
                                [www-authenticate] => OAuth2 realm="WSO2 API Manager", error="invalid token", error_description="The access token expired"
                                [x-wc-webhook-source] => https://site . com/
                                [referer] => URL
                                [x-forwarded-host] => host
                                [x-forwarded-proto] => https
                                [x-wc-webhook-topic] => order.created
                                [x-wc-webhook-signature] => SIGNATURE
                                [accept-encoding] => deflate, gzip
                                [x-wc-webhook-event] => created
                                [access-control-allow-headers] => authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction
                                [x-wc-webhook-delivery-id] => ID
                                [expect] => 100-continue
                                [x-wc-webhook-id] => 1
                                [x-forwarded-for] => Array
                                    (
                                        [0] => test
                                        [1] => test
                                    )

                                [x-wc-webhook-resource] => order
                                [x-forwarded-server] => server
                                [content-type] => application/xml; charset=UTF-8
                            )

                    )
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算