2017 © Pedro Peláez
 

library php-guzzlecomponents

Extensions for PHP Guzzle lib

image

sokil/php-guzzlecomponents

Extensions for PHP Guzzle lib

  • Sunday, October 5, 2014
  • by sokil
  • Repository
  • 1 Watchers
  • 0 Stars
  • 249 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Guzzle 3 Components

Installation

Installation can be made through Composer:, (*1)

require: {
    "sokil/php-guzzlecomponents": "dev-master"
}

Signing request

This plugin used to sign request on client. For example server gives access to API for that applications who knows "Application ID" and corresponding "Key"., (*2)

Guzzle client must add configured plugin:, (*3)

$client->addSubscriber(new \Sokil\Guzzle\Plugin\RequestSign(array(
    'key'               => $cryptKey,
    'algo'              => 'sha1',
    'queryParamName'    => 'sign',
    'additionalParams'  => [
        'app_id'    => $applicationId,
    ]
)));
Parameter Type Required Default value Description
key string required Key which used to crypt message
algo string optional sha1 Crypt algorythm
queryParamName string optional sign Name of query string parameter where signatupe passed
additionalParams array optional Parameters, additionaly send in query string and signed if request passed through GET method

Algorithm of validation signed request on server:, (*4)

// check if fields passed in query
if(empty($_GET['sign']) || empty($_GET['app_id']) {
    Header('HTTP/1.0 403 Forbidden');
    exit;
}

// get crypt key from storage by application id
$applicationId = $_GET['app_id'];
$cryptKey = get_crypt_key($applicationId);

// get message
if('POST' === $_SERVER['REQUEST_METHOD']) {
    $body = file_get_contents('php://input');
} else {
    $body = $_GET;
    // sign key not crypted so it must be unset from message
    unset($body['sign']);
    // params must be sorted
    ksort($body);
    // query gathered to string
    $body = http_build_query($body);
}

// calculate and compare sign with passed
return ($_GET['sign'] === hash_hmac('sha1', $body, $cryptKey));

The Versions

05/10 2014

dev-master

9999999-dev

Extensions for PHP Guzzle lib

  Sources   Download

MIT

The Requires

 

by Dmytro Sokil

18/05 2014

0.3

0.3.0.0

Extensions for PHP Guzzle lib

  Sources   Download

MIT

The Requires

 

by Avatar sokil

17/05 2014

0.2

0.2.0.0

Extensions for PHP Guzzle lib

  Sources   Download

MIT

The Requires

 

by Avatar sokil