note 114976 added to soapclient.soapclient
| From: | Peter | Date: | Thu, 08 May 2014 14:18:59 +0000 |
| Subject: | note 114976 added to soapclient.soapclient | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199484@lists.php.net to get a copy of this message | ||
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
----
Server IP: 91.199.167.223
Probable Submitter: 95.97.155.24
----
Manual Page -- http://php.net/manual/en/soapclient.soapclient.php
Edit -- https://master.php.net/note/edit/114976
Del: integrated -- https://master.php.net/note/delete/114976/integrated
Del: useless -- https://master.php.net/note/delete/114976/useless
Del: bad code -- https://master.php.net/note/delete/114976/bad+code
Del: spam -- https://master.php.net/note/delete/114976/spam
Del: non-english -- https://master.php.net/note/delete/114976/non-english
Del: in docs -- https://master.php.net/note/delete/114976/in+docs
Del: other reasons-- https://master.php.net/note/delete/114976
Reject -- https://master.php.net/note/reject/114976
Search -- https://master.php.net/manage/user-notes.php