Sign and verify PSR-7 HTTP messages in PHP.

Paul Annesley faa3d514fd Merge branch 'query-string-ordering' 9 years ago
src fcd0ea973a SigningString avoids Symfony's getQueryString() mangling. 9 years ago
tests fcd0ea973a SigningString avoids Symfony's getQueryString() mangling. 9 years ago
.gitignore 4647f8eea8 vendor/ directory ignored by git. 10 years ago
.travis.yml 8ab81f4591 Travis CI configuration. 10 years ago
LICENSE.txt 90404d56a5 MIT license. 10 years ago
README.md dbf83633a4 Link to http-signatures-guzzle lib 10 years ago
composer.json 38b7f9243d symfony/http-foundation in composer.json 10 years ago
phpunit.xml.dist b60ddac907 phpunit.xml.dist and tests/bootstrap.php 10 years ago

README.md

HTTP Signatures

PHP implementation of HTTP Signatures draft specification; cryptographically sign and verify HTTP requests and responses.

See also:

Usage

Add 99designs/http-signatures to your composer.json.

Configure a context with your algorithm, keys, headers to sign. This is best placed in an application startup file.

use HttpSignatures\Context;

$context = new Context(array(
  'keys' => array('examplekey' => 'secret-key-here'),
  'algorithm' => 'hmac-sha256',
  'headers' => array('(request-target)', 'Date', 'Accept'),
));

If there's only one key in the keys hash, that will be used for signing. Otherwise, specify one via 'signingKeyId' => 'examplekey'.

Messages

A message is an HTTP request or response. A subset of the interface of Symfony\Component\HttpFoundation\Request is expected; the ability to read headers via $message->headers->get($name) and set them via $message->headers->set($name, $value), and for signing requests, methods to read the path, query string and request method.

use Symfony\Component\HttpFoundation\Request;

$message = Request::create('/path?query=123', 'GET');
$message->headers->replace(array(
  'Date' => 'Wed, 30 Jul 2014 16:40:19 -0700',
  'Accept' => 'llamas',
));

Signing a message

$context->signer()->sign($message);

Now $message contains the signature headers:

$message->headers->get('Signature');
# keyId="examplekey",algorithm="hmac-sha256",headers="...",signature="..."

$message->headers->get('Authorization');
# Signature keyId="examplekey",algorithm="hmac-sha256",headers="...",signature="..."

Verifying a signed message

$context->verifier()->isValid($message); // true or false

Contributing

Pull Requests are welcome.