AuthTokenSubscriber
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.
array
getEvents()
No description
onBefore(BeforeEvent $event)
Updates the request with an Authorization header when auth is 'fetched_auth_token'.
Example:
use GuzzleHttp\Client;
use Google\Auth\OAuth2;
use Google\Auth\Subscriber\AuthTokenSubscriber;
$config = [..<oauth config param>.];
$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');