Allows to easily add Ws Security header to a SOAP Request
WsSecurity adds the WSSE authentication header to your SOAP request
This repository contains multiple classes that may be used indepdently but for now it is easier/better to only use the WsSecurity class.
The WsSecurity class provides a static method that takes the parameters that should suffice to create your Ws-Security Username Authentication header required in your SOAP request.
Concretly, you must include this repository in your project using composer (composer require wsdltophp/wssecurity
) then use it such as:
use WsdlToPhp\WsSecurity\WsSecurity;
/**
* @var \SoapHeader
*/
$soapHeader = WsSecurity::createWsSecuritySoapHeader('login', 'password', true);
/**
* Send the request
*/
$soapClient = new \SoapClient('wsdl_url');
$soapClient->__setSoapHeaders($soapHeader);
$soapClient->__soapCall('echoVoid', []);
The WsSecurity::createWsSecuritySoapHeader
parameters are defined in this order ($username, $password, $passwordDigest = false, $addCreated = 0, $addExpires = 0, $returnSoapHeader = true, $mustunderstand = false, $actor = null, $usernameId = null, $addNonce = true)
:
true
if your password must be encryptedThanks to the Docker image of phpfarm, tests can be run locally under any PHP version using the cli:
First of all, you need to create your container which you can do using docker-compose by running the below command line from the root directory of the project:
$ docker-compose up -d --build
You then have a container named ws_security
in which you can run composer
commands and php cli
commands such as:
# install deps in container (using update ensure it does use the composer.lock file if there is any)
$ docker exec -it ws_security php-7.4 /usr/bin/composer update
# run tests in container
$ docker exec -it ws_security php-7.4 -dmemory_limit=-1 vendor/bin/phpunit
If you have a question, feel free to create an issue.
The MIT License (MIT). Please see License File for more information.