99designs/http-signatures-guzzlehttp
最新稳定版本:2.0.1
Composer 安装命令:
composer require 99designs/http-signatures-guzzlehttp
包简介
Sign and verify HTTP messages with Guzzle 6
README 文档
README
Guzzle 6 support for 99designs http-signatures library
Adds 99designs/http-signatures support to Guzzle 6.
Older Guzzle Versions
For Guzzle 4 & 5 use the v1.x release of this repo.
For Guzzle 3 see the 99designs/http-signatures-guzzle repo.
Signing with Guzzle 6
This library includes support for automatically signing Guzzle requests using Middleware.
You can use GuzzleHttpSignatures::defaultHandlerFromContext to easily create the default Guzzle handler with the
middleware added to sign every request.
use GuzzleHttp\Client; use HttpSignatures\Context; use HttpSignatures\GuzzleHttpSignatures; require __DIR__ . "/../vendor/autoload.php"; $context = new Context([ 'keys' => ['examplekey' => 'secret-key-here'], 'algorithm' => 'hmac-sha256', 'headers' => ['(request-target)', 'date'], ]); $handlerStack = GuzzleHttpSignatures::defaultHandlerFromContext($context); $client = new Client(['handler' => $handlerStack]); // The below will now send a signed request to: http://example.org/path?query=123 $response = $client->get("http://www.example.com/path?query=123", ['headers' => ['date' => 'today']]);
Or if you're creating a custom HandlerStack you can add the Middleware yourself:
<?php use GuzzleHttp\Client; use GuzzleHttp\Handler\CurlHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use HttpSignatures\Context; use HttpSignatures\GuzzleHttpSignatures; require __DIR__ . "/../vendor/autoload.php"; $context = new Context([ 'keys' => ['examplekey' => 'secret-key-here'], 'algorithm' => 'hmac-sha256', 'headers' => ['(request-target)', 'date'], ]); $handlerStack = new HandlerStack(); $stack->setHandler(new CurlHandler()); $stack->push(GuzzleHttpSignatures::middlewareFromContext($this->context)); $stack->push(Middleware::history($this->history)); $client = new Client(['handler' => $handlerStack]); // The below will now send a signed request to: http://example.org/path?query=123 $response = $client->get("http://www.example.com/path?query=123", ['headers' => ['date' => 'today']]);
Contributing
Pull Requests are welcome.
统计信息
- 总下载量: 203.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 1
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-18