Copied!

ProxyAuthTokenMiddleware is a Guzzle Middleware that adds an Authorization header provided by an object implementing FetchAuthTokenInterface.

The FetchAuthTokenInterface#fetchAuthToken is used to obtain a hash; one of the values value in that hash is added as the authorization header.

Requests will be accessed with the authorization header:

'proxy-authorization' 'Bearer '

CloneableInstantiable
Methods
public __construct(Google\Auth\FetchAuthTokenInterface $fetcher, ?callable $httpHandler = NULL, ?callable $tokenCallback = NULL)
 

Creates a new ProxyAuthTokenMiddleware.

  • param \FetchAuthTokenInterface $fetcher is used to fetch the auth token
  • param callable|null $httpHandler (optional) callback which delivers psr7 request
  • param callable|null $tokenCallback (optional) function to be called when a new token is fetched.
public __invoke(callable $handler)
 

Updates the request with an Authorization header when auth is 'google_auth'.

use Google\Auth\Middleware\ProxyAuthTokenMiddleware; use Google\Auth\OAuth2; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack;

$config = [...]; $oauth2 = new OAuth2($config) $middleware = new ProxyAuthTokenMiddleware($oauth2); $stack = HandlerStack::create(); $stack->push($middleware);

$client = new Client([ 'handler' => $stack, 'base_uri' => 'https://www.googleapis.com/taskqueue/v1beta2/projects/', 'proxy_auth' => 'google_auth' // authorize all requests ]);

$res = $client->get('myproject/taskqueues/myqueue');

  • param callable $handler
  • return \Closure
Properties
private $fetcher = NULL
 
  • var \FetchAuthTokenInterface
private $httpHandler = NULL
 
  • var callable
private $tokenCallback = NULL
 
  • var ?callable
Methods
private fetchToken()
 

Call fetcher to fetch the token.

  • return string|null
private getQuotaProject()
 
  • @return
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration