AuthTokenSubscriber
in package
implements
SubscriberInterface
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
Table of Contents
Interfaces
- SubscriberInterface
Properties
- $fetcher : FetchAuthTokenInterface
- $httpHandler : callable
- $tokenCallback : callable
Methods
- __construct() : mixed
- Creates a new AuthTokenSubscriber.
- getEvents() : array<string|int, mixed>
- onBefore() : mixed
- Updates the request with an Authorization header when auth is 'fetched_auth_token'.
- getQuotaProject() : mixed
Properties
$fetcher
private
FetchAuthTokenInterface
$fetcher
$httpHandler
private
callable
$httpHandler
$tokenCallback
private
callable
$tokenCallback
Methods
__construct()
Creates a new AuthTokenSubscriber.
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) http client to fetch the token.
- $tokenCallback : callable = null
-
(optional) function to be called when a new token is fetched.
getEvents()
public
getEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>onBefore()
Updates the request with an Authorization header when auth is 'fetched_auth_token'.
public
onBefore(BeforeEvent $event) : mixed
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');
Parameters
- $event : BeforeEvent
getQuotaProject()
private
getQuotaProject() : mixed