class AuthTokenSubscriber implements SubscriberInterface (View source)

AuthTokenSubscriber is a Guzzle Subscriber 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 '

Methods

__construct(FetchAuthTokenInterface $fetcher, callable $httpHandler = null, callable $tokenCallback = null)

Creates a new AuthTokenSubscriber.

array
getEvents()

No description

onBefore(BeforeEvent $event)

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

Details

__construct(FetchAuthTokenInterface $fetcher, callable $httpHandler = null, callable $tokenCallback = null)

Creates a new AuthTokenSubscriber.

Parameters

FetchAuthTokenInterface $fetcher

is used to fetch the auth token

callable $httpHandler

(optional) http client to fetch the token.

callable $tokenCallback

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

array getEvents()

No description

Return Value

array

onBefore(BeforeEvent $event)

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

use GuzzleHttp\Client; use Google\Auth\OAuth2; use Google\Auth\Subscriber\AuthTokenSubscriber;

$config = [...]; $oauth2 = new OAuth2($config) $subscriber = new AuthTokenSubscriber($oauth2);

$client = new Client([ 'base_url' => 'https://www.googleapis.com/taskqueue/v1beta2/projects/', 'defaults' => ['auth' => 'google_auth'] ]); $client->getEmitter()->attach($subscriber);

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

Parameters

BeforeEvent $event