devster/buzz-wsse-plugin

Buzz plugin to manage WSSE authentication

1.0.0 2014-01-12 22:55 UTC

This package is auto-updated.

Last update: 2024-03-29 00:48:47 UTC


README

Latest Stable Version Build Status

Buzz plugin to manage WSSE authentication

Buzz is a lightweight PHP 5.3 library for issuing HTTP requests.

More informations on WSSE authentication http://www.xml.com/pub/a/2003/12/17/dive.html

Installation

Install via composer

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add the plugin as a dependency
php composer.phar require devster/buzz-wsse-plugin:~1.0

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Basic usage

require 'vendor/autoload.php'

use Buzz\Browser;
use Devster\Buzz\Listener\WsseAuthListener;

// Create a Buzz client
$browser = new Browser();
// and add the Wsse listener
$browser->addListener(new WsseAuthListener('username', '*******'));

// finally use Buzz as usual
$response = $browser->get('http://www.google.com');

echo $browser->getLastRequest()."\n";
echo $response;

Customization

All the plugin is configurable: the way to generate the nonce, the timestamp and also the password digest.

use Buzz\Browser;
use Buzz\Message\RequestInterface;
use Devster\Buzz\Listener\WsseAuthListener;

$browser = new Buzz\Browser();
$wsse = new WsseAuthListener('bob', '*********');
$wsse
    // Customize the nonce generator
    // A callable that must return a string
    ->setNonceCallback(function(RequestInterface $request) {
        return uniqid('myapp_', true);
    })
    // Customize the timestamp generator
    // A callable that must return a string
    ->setTimestampCallback(function(RequestInterface $request) {
        $date = new \DateTime("now");
        return $date->format('c');
    })
    // Customize the digest generator
    // A callable that must return a string
    ->setDigestCallback(function($nonce, $timestamp, $password, RequestInterface $request) {
        return hash('sha512', $nonce.$timestamp.$password, true);
    })
;

// add the listener to the browser
$browser->addListener($wsse);

Tests

Unit tests are made with atoum.

composer install --dev
./vendor/bin/atoum

License

This plugin is licensed under the MIT License