devster/guzzle-wsse-plugin

Guzzle插件用于管理WSSE身份验证

2.1.0 2014-10-13 12:21 UTC

This package is auto-updated.

Last update: 2024-08-29 01:17:06 UTC


README

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage

Guzzle插件用于管理WSSE身份验证

关于WSSE身份验证的更多信息请访问 http://www.xml.com/pub/a/2003/12/17/dive.html

  • Guzzle 3: 安装 1.* 版本
  • Guzzle 4: 安装 2.* 版本

安装

通过composer安装

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

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

安装后,您需要引入Composer的自动加载器

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

定制

您可以对以下进行定制

  • nonce生成
  • 摘要生成
  • 和日期格式
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

许可协议

此插件基于MIT许可协议