-
-
Save lucasjsandrade/2ba9088f2e7b060beecaf4dad8db5d36 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