WSSE web service call from different servers?

396 Views Asked by At

I have written the WSSE authentication provider in synfony 2.3. http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

I have generated header and calling web service. It is working properly in same machine and when calling different machine, it is getting Internal Server Error

{"error":{"code":500,"message":"Internal Server Error"}} This is the header generation functions:

 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);
}

And this is the API call

$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);

I cant understand why? Is there any effect from Timestamp when calling from another country server? Please help

0

There are 0 best solutions below