public function attachTokentoSig($token) { if (!$token instanceof DOMElement) { throw new Exception('Invalid parameter: BinarySecurityToken element expected'); } $objXMLSecDSig = new XMLSecurityDSig(); if ($objDSig = $objXMLSecDSig->locateSignature($this->soapDoc)) { $tokenURI = '#' . $token->getAttributeNS(self::WSUNS, 'Id'); $this->SOAPXPath->registerNamespace('secdsig', XMLSecurityDSig::XMLDSIGNS); $query = './secdsig:KeyInfo'; $nodeset = $this->SOAPXPath->query($query, $objDSig); $keyInfo = $nodeset->item(0); if (!$keyInfo) { $keyInfo = $objXMLSecDSig->createNewSignNode('KeyInfo'); $objDSig->appendChild($keyInfo); } $tokenRef = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX . ':SecurityTokenReference'); $keyInfo->appendChild($tokenRef); $reference = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX . ':Reference'); $reference->setAttribute('ValueType', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3'); $reference->setAttribute('URI', $tokenURI); $tokenRef->appendChild($reference); } else { throw new Exception('Unable to locate digital signature'); } }