devster/guzzle-wsse-plugin

Guzzle plugin to manage WSSE authentication

2.1.0 2014-10-13 12:21 UTC

This package is auto-updated.

Last update: 2024-11-29 02:11:27 UTC


README

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage

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

Installation

Install via composer

# 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';

Basic usage

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();

Customization

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);
    })
;

Tests

composer install && vendor/bin/phpunit

License

This plugin is licensed under the MIT License