2017 © Pedro Peláez
 

library guzzle-http-authentication-middleware

Http authentication middleware for Guzzle6

image

webignition/guzzle-http-authentication-middleware

Http authentication middleware for Guzzle6

  • Monday, June 25, 2018
  • by webignition
  • Repository
  • 1 Watchers
  • 0 Stars
  • 623 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 616 % Grown

The README.md

Guzzle HTTP Authentication Middleware

Overview

Middleware for Guzzle 6 for setting basic http authentication on all requests sent by a client., (*1)

An authentication header is added to any valid request. A valid request is one where the request host matches a pre-specified domain name., (*2)

Useful if your circumstances match all or some of the following:, (*3)

  • you need to set HTTP authentication on all requests sent by a client for a specific domain only
  • you don't want to specifically add an authorization header to each request made, particularly if there are many points across an application where requests are made
  • you cannot determine in advance to which domains requests might be made and you don't want to leak credentials by means of setting an authorization header on every single request that your client sends

Maybe, just maybe, this is for you., (*4)

Usage example

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use webignition\Guzzle\Middleware\HttpAuthentication\AuthorizationType;
use webignition\Guzzle\Middleware\HttpAuthentication\AuthorizationHeader;
use webignition\Guzzle\Middleware\HttpAuthentication\CredentialsFactory;
use webignition\Guzzle\Middleware\HttpAuthentication\HttpAuthenticationMiddleware;

// Creating a client that uses the middleware
$httpAuthenticationMiddleware = new HttpAuthenticationMiddleware();

$handlerStack = HandlerStack::create();
$handlerStack->push($httpAuthenticationMiddleware, 'http-auth');

$client = new Client([
    'handler' => $handlerStack,
]);

// Setting credentials on the middleware
$basicCredentials = CredentialsFactory::createBasicCredentials('username', 'password');
$httpAuthenticationMiddleware->setType(AuthorizationType::BASIC);
$httpAuthenticationMiddleware->setCredentials($credentials);
$httpAuthenticationMiddleware->setHost('example.com');

// All requests to example.com (or *.example.com) will now have
// a correct Authorization header set for basic HTTP authentication

Application-level considerations

Let's assume you are building a modern PHP application that utilises controllers, services and so on., (*5)

Define your HttpAuthenticationMiddleware instance as a service. Use dependency injection to inject that service into whichever part of your application needs to set HTTP authentication credentials. Call HttpAuthenticationMiddleware::setHttpAuthenticationCredentials() as needed, passing in a HttpAuthenticationCredentials instance containing relevant values., (*6)

The Versions

25/06 2018

dev-master

9999999-dev https://github.com/webignition/guzzle-http-authentication-middleware

Http authentication middleware for Guzzle6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jon Cram

middleware psr7 guzzle http authentication

25/06 2018

0.2

0.2.0.0 https://github.com/webignition/guzzle-http-authentication-middleware

Http authentication middleware for Guzzle6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jon Cram

middleware psr7 guzzle http authentication

11/05 2018

dev-document

dev-document https://github.com/webignition/guzzle-http-authentication-middleware

Http authentication middleware for Guzzle6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jon Cram

middleware psr7 guzzle http authentication

11/05 2018

0.1

0.1.0.0 https://github.com/webignition/guzzle-http-authentication-middleware

Http authentication middleware for Guzzle6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jon Cram

sitemap