Skip to content

devster/guzzle-wsse-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guzzle WSSE Plugin

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

About

Guzzle Plugin to manage WSSE Authentication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages