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 '

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

Creates a new AuthTokenMiddleware.

    public __invoke(callable $handler)

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

    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();

    $client = new Client([

    'handler' => $stack,
    'base_uri' => '',
    'auth' => 'google_auth' // authorize all requests


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

    • return Closure
    private $fetcher
    • var FetchAuthTokenInterface
    private $httpHandler
    • var callable
    private $tokenCallback
    • var callable
    private fetchToken()

    Call fetcher to fetch the token.

    • return string
    private getQuotaProject()
    © 2020 Bruce Wells
    Search Namespaces \ Classes
    ConfigurationNumbers (0-9.) only