PHP Classes

WsSecurity: Create header to set password for SOAP requests

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 181 All time: 8,707 This week: 115Up
Version License PHP version Categories
wssecurity 1.0.0MIT/X Consortium ...5PHP 5, User Management, Web services
Description 

Author

This package can create header to set password for SOAP requests.

It takes the user name and a password and generate a header for sending a SOAP request to a server and authenticate on behalf of the given user.

The class takes an optional parameter to use digest authentication and the password be encrypted when the request is sent.

Innovation Award
PHP Programming Innovation award nominee
July 2017
Number 9
Many Web services are provided by servers that implement the SOAP protocol.

PHP provides built-in support to sending HTTP SOAP requests to remote servers. However it does not come with direct support to enter the credentials to servers that require user authentication.

This package can create a header to set user name and password for SOAP requests to servers that require them.

Manuel Lemos
Picture of WsdlToPhp
  Performance   Level  
Name: WsdlToPhp <contact>
Classes: 9 packages by
Country: France France
Age: 41
All time rank: 73731 in France France
Week rank: 215 Up10 in France France Up
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Documentation

WsdlToPhp WsSecurity

License Latest Stable Version Build Status PHP 7 ready Scrutinizer Code Quality Code Coverage Total Downloads Dependency Status StyleCI SensioLabsInsight

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:dev-master) 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);
$client->__soapCall('echoVoid', null);

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

  • $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 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 object that is used to create the \SoapHeader object, then you'll have to use to create by yourself the \SoapHeader object
  • $mustunderstand: classic option of the \SoapClient class
  • $actor: classic option of the \SoapClient class
  • $usernameId: the id to attach to the UsernameToken element, optional

Unit tests

You can run the unit tests with the following command at the root directory of this project:

$ phpunit

Feedback

Any feedback is appreciated at contact@wsdltophp.com or by creating an issue on this project.


  Files folder image Files (20)  
File Role Description
Files folder imagesrc (10 files)
Files folder imagetests (2 files)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .php_cs Example Example script
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (20)  /  src  
File Role Description
  Plain text file Created.php Class Class source
  Plain text file Element.php Class Class source
  Plain text file Expires.php Class Class source
  Plain text file Nonce.php Class Class source
  Plain text file Password.php Class Class source
  Plain text file Security.php Class Class source
  Plain text file Timestamp.php Class Class source
  Plain text file Username.php Class Class source
  Plain text file UsernameToken.php Class Class source
  Plain text file WsSecurity.php Class Class source

  Files folder image Files (20)  /  tests  
File Role Description
  Plain text file TestCase.php Class Class source
  Plain text file WsSecurityTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:181
This week:0
All time:8,707
This week:115Up