Guzzle Plugin to manage WSSE Authentication
More informations on WSSE authentication http://www.xml.com/pub/a/2003/12/17/dive.html
- Guzzle 3: install
1.*
version - Guzzle 4: install
2.*
version
# Install Composer
curl -sS https://getcomposer.org/installer | php
# Add the plugin as a dependency
php composer.phar require devster/guzzle-wsse-plugin:~2.0
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use Devster\GuzzleHttp\Subscriber\WsseAuth;
// Create a Guzzle client
$client new Client(['base_url' => 'http://example.com']);
// and add it the plugin
(new WsseAuth('username', 'pass****'))->attach($client);
// Or
$client->getEmitter()->attach(new WsseAuth('username', '********'));
// Now the plugin will add the correct WSSE headers to your guzzle request
$response = $client->get('/data')->send();
You can customize:
- The nonce generation
- The digest generation
- And the date format
use GuzzleHttp\Client;
use GuzzleHttp\Message\RequestInterface;
use Devster\GuzzleHttp\Subscriber\WsseAuth;
$client = new Client;
$plugin = new WsseAuth('username', 'pass****');
$plugin
->attach($client)
->setNonce(function (RequestInterface $request) {
return uniqid('my_nonce', true);
})
->setDigest(function ($nonce, $createdAt, $password) {
return $nonce.$createdAt.$password;
})
->setDateFormat('Y-m-d') // PHP format. Default: c (ISO 8601)
// Process a behavior (like hashing) on the password before it pass to the digest generator
->setPasswordProcessor(function ($password) {
return sha1($password);
})
;
composer install && vendor/bin/phpunit
This plugin is licensed under the MIT License