Last active
March 12, 2022 19:17
-
-
Save gknapp/bb4e4f009fc870db39c1 to your computer and use it in GitHub Desktop.
Add WSSE support to PHP's soapclient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WsseHeader | |
{ | |
const NS_WSSE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; | |
const NS_WSSEPSWD = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'; | |
public function build($username, $password) | |
{ | |
$header = sprintf( | |
'<wsse:Security xmlns:wsse="%s" SOAP-ENV:mustUnderstand="1">' . | |
'<wsse:UsernameToken>' . | |
'<wsse:Username>%s</wsse:Username>' . | |
'<wsse:Password Type="%s">%s</wsse:Password>' . | |
'</wsse:UsernameToken>' . | |
'</wsse:Security>', | |
self::NS_WSSE, $username, self::NS_WSSEPSWD, $password | |
); | |
return new SoapHeader(self::NS_WSSE, 'wsse', new SoapVar($header, XSD_ANYXML)); | |
} | |
} | |
class WsseClient extends SoapClient | |
{ | |
public function setCredentials($username, $password) | |
{ | |
$wsseHeader = new WsseHeader; | |
$header = $wsseHeader->build($username, $password); | |
$this->__setSoapHeaders(null); | |
$this->__setSoapHeaders($header); | |
} | |
} | |
// Construct as you would the built-in SoapClient, call setCredentials() when known | |
// http://www.php.net/manual/en/soapclient.soapclient.php | |
$soap = new WsseClient($wsdl, $options); | |
// ... once credentials are known | |
$soap->setCredentials($user, $pswd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi deynerreinoso, i tried to implement this class but not success, I needed to find another solution,
I created the entire xml structure manually, whith DOMDocument and I called a soap request with Curl,
`
public function FunResolverObjeto($VObjectType,$VPropertyString,$servico){
`
I couldn't find any other way to make that connection.
is working well for me this code.