我在 synfony 2.3 中编写了 WSSE 身份验证提供程序。 http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html
我已经生成了标头并调用了 Web 服务。它在同一台机器上正常工作,当调用不同的机器时,它得到内部服务器错误
{"error":{"code":500,"message":"Internal Server Error"}} 这是头生成函数:
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);
我不明白为什么?从另一个国家的服务器调用时,时间戳有什么影响吗?请帮忙