note 114976 deleted from soapclient.soapclient by crell

From: Date: Mon, 04 Apr 2022 16:51:32 +0000
Subject: note 114976 deleted from soapclient.soapclient by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218105@lists.php.net to get a copy of this message
Note Submitter: Peter ---- if you need to use ws-security with a nonce and a timestamp, you can use this : <?php class WsseAuthHeader extends SoapHeader { private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; private $wsu_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'; function __construct($user, $pass) { $created = gmdate('Y-m-d\TH:i:s\Z'); $nonce = mt_rand(); $passdigest = base64_encode( pack('H*', sha1( pack('H*', $nonce) . pack('a*',$created). pack('a*',$pass)))); $auth = new stdClass(); $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $auth->Nonce = new SoapVar($passdigest, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $auth->Created = new SoapVar($created, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wsu_ns); $username_token = new stdClass(); $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns); $security_sv = new SoapVar( new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns); parent::__construct($this->wss_ns, 'Security', $security_sv, true); } } ?> and with your SoapClient do : <?php $client = new SoapClient("http://host/path"); $client->__setSoapHeaders(Array(new WsseAuthHeader("user", "pass"))); ?> works for me. based on a stackoverlfow post which only did the username and password, not the nonce and the timestamp

« previous php.notes (#218105) next »