Documentation

AuthTokenMiddleware
in package

AuthTokenMiddleware 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:

'authorization' 'Bearer '

Table of Contents

Properties

$fetcher  : FetchAuthTokenInterface
$httpHandler  : callable
$tokenCallback  : callable

Methods

__construct()  : mixed
Creates a new AuthTokenMiddleware.
__invoke()  : Closure
Updates the request with an Authorization header when auth is 'google_auth'.
fetchToken()  : string
Call fetcher to fetch the token.
getQuotaProject()  : mixed

Properties

Methods

__construct()

Creates a new AuthTokenMiddleware.

public __construct(FetchAuthTokenInterface $fetcher[, callable $httpHandler = null ][, callable $tokenCallback = null ]) : mixed
Parameters
$fetcher : FetchAuthTokenInterface

is used to fetch the auth token

$httpHandler : callable = null

(optional) callback which delivers psr7 request

$tokenCallback : callable = null

(optional) function to be called when a new token is fetched.

__invoke()

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

public __invoke(callable $handler) : Closure

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

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

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

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

Parameters
$handler : callable
Return values
Closure

fetchToken()

Call fetcher to fetch the token.

private fetchToken() : string
Return values
string

        
On this page

Search results