Jump to content

GET HTTPHEADERS - WSSE Authentication


chinoknot

Recommended Posts

Hello,

I'm in trouble with WSSE Authentication in PHP. I found a good client and server file for my tests and works fine, but I receive the call in other way, so I must configure my serverside for receiving the right header with username, psw, nonce and created time.

The call:

 

<?php
class TokenGenerator {
	public static function generateToken($username, $password) {
		$nonce = self::generateNonce ();

		$created = date ( 'Y-m-d\TH:i:sP' );
		$digest = base64_encode ( sha1 ( $nonce . $created . $password, TRUE ) );
		$token = sprintf ( 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $username, $digest, $nonce, $created );
		return $token;
	}

	private static function generateNonce($bits = 256) {
		$bytes = ceil ( $bits / 8 ) * microtime ();
		$return = '';

		for($i = 0; $i < $bytes; $i ++)
			$return .= chr ( mt_rand ( 0, 255 ) );

		return md5 ( $return );
	}
}

$xwsse = TokenGenerator::generateToken ( 'username', 'RC&EWoiQ7#!!' ); // ### GENERO IL TOKEN
$httpRequest = new \HttpRequest (
	'http://XXXX/',
	\HttpRequest::METH_POST, [
		'headers' => [
			'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
			'Accept-Charset' => 'UTF-8',
			'X-Wsse' => $xwsse
		],
		'protocol' => HTTP_VERSION_1_2
	]
);

$httpRequest->setPostFields ( [
	'userName' => 'testAgentnip',
	'phoneNumber' => '3474875366',
	'customer' => '112233'
] ) or die ( 'Errore' );

try {
	$result = $httpRequest->send()->getBody ();
	echo $result;
} catch ( \HttpException $ex ) {
	error_log ( 'ERRORE CHIAMATA HTTP => ' . $ex->getMessage () );
}

Now I need a page which receive this kind of header.

I've been looking for getallheaders() function, but still doesn't work

Help me!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.