PHPackages                             wsdltophp/wssecurity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. wsdltophp/wssecurity

ActiveLibrary[HTTP &amp; Networking](/categories/http)

wsdltophp/wssecurity
====================

Allows to easily add Ws Security header to a SOAP Request

2.0.6(1y ago)42837.2k—5%12[1 PRs](https://github.com/WsdlToPhp/WsSecurity/pulls)8MITPHPPHP &gt;=7.4

Since Apr 1Pushed 1y ago6 watchersCompare

[ Source](https://github.com/WsdlToPhp/WsSecurity)[ Packagist](https://packagist.org/packages/wsdltophp/wssecurity)[ RSS](/packages/wsdltophp-wssecurity/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (17)Used By (8)

WsSecurity
==========

[](#wssecurity)

> WsSecurity adds the WSSE authentication header to your SOAP request

[![License](https://camo.githubusercontent.com/136613bb0b6825d84340dbc94edcfbb528b44af855c5785a71c5f8c3a3d1b435/68747470733a2f2f706f7365722e707567782e6f72672f7773646c746f7068702f777373656375726974792f6c6963656e7365)](https://packagist.org/packages/wsdltophp/wssecurity)[![Latest Stable Version](https://camo.githubusercontent.com/dadb029bced1bea84a608fe486512f7af9e914e16a79d16fc0a2c5a030f70068/68747470733a2f2f706f7365722e707567782e6f72672f7773646c746f7068702f777373656375726974792f76657273696f6e2e706e67)](https://packagist.org/packages/wsdltophp/wssecurity)[![TeamCity build status](https://camo.githubusercontent.com/d06f1da778a547703199e415519c116a3534c26339810bf87dc2c4d478bad657/68747470733a2f2f7465616d636974792e6d696b61656c2d64656c736f6c2e66722f6170702f726573742f6275696c64732f6275696c64547970653a69643a577353656375726974795f4275696c642f73746174757349636f6e2e737667)](https://github.com/WsdlToPhp/WsSecurity)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d66dde6222bd0d6aeee29eed74d56065fb088d5bc5274f84b53e71c4e4a15239/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5773646c546f5068702f577353656375726974792f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/WsdlToPhp/WsSecurity/)[![Code Coverage](https://camo.githubusercontent.com/7e2a201254e104a0aba89f7d0ac52c8e14811450f472e52b813cc3890f53ffbd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5773646c546f5068702f577353656375726974792f6261646765732f636f7665726167652e706e67)](https://scrutinizer-ci.com/g/WsdlToPhp/WsSecurity/)[![Total Downloads](https://camo.githubusercontent.com/62f683f61dff02da243824c061f2d197080d19b1af8d4feaa121f981947a8c2d/68747470733a2f2f706f7365722e707567782e6f72672f7773646c746f7068702f777373656375726974792f646f776e6c6f616473)](https://packagist.org/packages/wsdltophp/wssecurity)[![StyleCI](https://camo.githubusercontent.com/54ec524d3fe673a552878202a16de04a94ba4b8eaba1f494c5315357ca963336/68747470733a2f2f7374796c6563692e696f2f7265706f732f34333831313430342f736869656c64)](https://styleci.io/repos/43811404)[![SymfonyInsight](https://camo.githubusercontent.com/f325a9e5df2e1925e4183dc0b0fbfe374ebd238e138e6410d426371b3570e562/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f35376464343332642d336434322d343439662d626161302d3435363861626562336133322f6d696e692e737667)](https://insight.symfony.com/projects/57dd432d-3d42-449f-baa0-4568abeb3a32)

How to use it
-------------

[](#how-to-use-it)

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)`:

- **$username**: your login/username
- **$password**: your password
- **$passwordDigest**: set it to `true` if your password must be encrypted
- **$addCreated**: set it to the time you created this header using the PHP [time](http://php.net/manual/en/function.time.php) function for example, otherwise pass 0
- **$addExpires**: set it to the number of seconds in which the header will expire, 0 otherwise
- **$returnSoapHeader**: set it to false if you want to get the [\\SoapVar](http://php.net/manual/en/class.soapvar.php) object that is used to create the [\\SoapHeader](http://php.net/manual/en/class.soapheader.php) object, then you'll have to use to create by yourself the [\\SoapHeader](http://php.net/manual/en/class.soapheader.php) object
- **$mustunderstand**: classic option of the [\\SoapClient](http://php.net/manual/en/soapclient.soapclient.php) class
- **$actor**: classic option of the [\\SoapClient](http://php.net/manual/en/soapclient.soapclient.php) class
- **$usernameId**: the id to attach to the UsernameToken element, optional
- **$addNonce**: *true* by default, if true, it adds the nonce element to the header, if false it does not add the nonce element to the header

Alternative usage
-----------------

[](#alternative-usage)

Create an instance of the Security class

```
use WsdlToPhp\WsSecurity\WsSecurity;

$wsSecurity = new WsSecurity('login', 'password', true, /*$addCreated*/ time());

// access its properties to alter them
$wsSecurity->getSecurity()->getTimestamp()->setAttribute('wsu:Id', 'AnyRequestValue');

// Get the SoapHeader
$header = $security->getSoapHeader($returnSoapHeader = true, $mustunderstand = false, $actor = null);
```

Testing using [Docker](https://www.docker.com/)
-----------------------------------------------

[](#testing-using-docker)

Thanks to the [Docker image](https://hub.docker.com/r/splitbrain/phpfarm) of [phpfarm](https://github.com/fpoirotte/phpfarm), tests can be run locally under *any* PHP version using the cli:

- php-7.4

First of all, you need to create your container which you can do using [docker-compose](https://docs.docker.com/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 /usr/bin/composer update
# run tests in container
$ docker exec -it ws_security php -dmemory_limit=-1 vendor/bin/phpunit
```

FAQ
---

[](#faq)

If you have a question, feel free to [create an issue](https://github.com/WsdlToPhp/WsSecurity/issues/new).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 94.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~256 days

Recently: every ~327 days

Total

13

Last Release

621d ago

Major Versions

1.2.2 → 2.0.02021-01-26

PHP version history (3 changes)1.0.0PHP &gt;=5.3

1.1.0PHP &gt;=5.4

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/f121510bbeb52d39582fbd1a2f31bc9fc4139f8ed4e89ef9c1406868c378669d?d=identicon)[wsdltophp](/maintainers/wsdltophp)

---

Top Contributors

[![mikaelcom](https://avatars.githubusercontent.com/u/584391?v=4)](https://github.com/mikaelcom "mikaelcom (110 commits)")[![tvaughan73](https://avatars.githubusercontent.com/u/850122?v=4)](https://github.com/tvaughan73 "tvaughan73 (4 commits)")[![baijunyao](https://avatars.githubusercontent.com/u/9360694?v=4)](https://github.com/baijunyao "baijunyao (1 commits)")[![liquid207](https://avatars.githubusercontent.com/u/48850370?v=4)](https://github.com/liquid207 "liquid207 (1 commits)")

---

Tags

soap-clientsoap-requestsoapclientsoapheaderwssecurityphpsoapwsse

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wsdltophp-wssecurity/health.svg)

```
[![Health](https://phpackages.com/badges/wsdltophp-wssecurity/health.svg)](https://phpackages.com/packages/wsdltophp-wssecurity)
```

###  Alternatives

[econea/nusoap

Fixed NuSOAP for PHP 5.6 - 8.5

3315.5M26](/packages/econea-nusoap)[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

76410.4k1](/packages/hannesvdvreken-guzzle-debugbar)[sebudesign/php-ntlm-soap

Composer based package of https://blogs.msdn.microsoft.com/freddyk/2010/01/19/connecting-to-nav-web-services-from-php/

1170.3k](/packages/sebudesign-php-ntlm-soap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
