来自不同服务器的WSSE Web服务调用?

时间:2014-12-10 06:14:15

标签: web-services rest symfony wsse

我在synfony 2.3中编写了WSSE身份验证提供程序。 http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

我已生成标头并调用Web服务。 它在同一台机器上正常工作,当调用不同的机器时,它正在获得内部服务器错误

{“error”:{“code”:500,“message”:“内部服务器错误”}}  这是标题生成函数:

 function make_nonce() {
    $chars = "123456789abcdefghijklmnopqrstuvwxyz";
    $random = "" . microtime();
    $random .= mt_rand();
    $mi = strlen($chars) - 1;
    for ($i = 0; $i < 10; $i++) {
        $random .= $chars[mt_rand(0, $mi)];
    }
    $nonce = md5($random);
    return $nonce;
}

function make_token($username, $password) {
    $nonce = make_nonce();
    $ts = date('c');
    $digest = base64_encode(sha1($nonce.$ts.$password, true));
    return sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
                   $username, $digest, base64_encode($nonce), $ts);
}

这是API调用

$contextData = array ( 
                'method' => 'POST',
                'header' => 'Content-Type: application/json',
    'Authorization: WSSE profile="UsernameToken"' ,
    'X-WSSE: '.  make_token('apiUser001', 'coloMbo657'),
                'content'=> $query );

// Create context resource for our request
$context = stream_context_create (array ( 'http' => $contextData ));

// Read page rendered as result of your POST request
 echo $result =  file_get_contents (
                  'http://abc.xxu.com/api/v1/users',  // page url
                  false,
                  $context);

我不明白为什么?从另一个国家/地区服务器呼叫时,时间戳是否有任何影响? 请帮忙

0 个答案:

没有答案
相关问题