moux2003/guzzle-bundle-sastoken-plugin

SAS Token Plugin for Guzzle Bundle, a PHP HTTP client library and framework for building RESTful web service clients

1.0.0 2018-02-20 13:17 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:19:44 UTC


README

Latest Version Software License

This plugin integrates SAS Token (Azure) functionality into Guzzle Bundle, a bundle for building RESTful web service clients.

Requirements

Installation

Using composer:

composer.json
{
    "require": {
        "moux2003/guzzle-bundle-sastoken-plugin": "~1.0"
    }
}
command line
$ composer require moux2003/guzzle-bundle-sastoken-plugin

Usage

Enable bundle

# app/AppKernel.php

new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle([
    new Moux2003\GuzzleBundleSasTokenPlugin\GuzzleBundleSasTokenPlugin(),
])

Basic configuration

# app/config/config.yml

eight_points_guzzle:
    clients:
        api_azure:
            base_url: "https://namespace.windows.net"

            # define headers, options

            # plugin settings
            plugin:
                sasToken:
                    connectionString: "Endpoint=scheme://namespace.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=HaShEdKey"
                    expires: 60 # optional

Usage with guzzle

<?php 

$sasToken = new \Moux2003\GuzzleBundleSasTokenPlugin\Middleware\SasTokenAuthMiddleware($connectionString);

$stack = \GuzzleHttp\HandlerStack::create();

// Add the sasToken middleware to the handler stack.
$stack->push($sasToken->attach());

$client   = new \GuzzleHttp\Client(['handler' => $stack]);
$response = $client->post('https://namespace.windows.net/hubname/messages?api-version=2013-10');

License

This middleware is licensed under the MIT License - see the LICENSE file for details