class AuthHandler

This class is responsible for three tasks:

  1. performing the initial authentication for OpenStack services
  2. populating the X-Auth-Token header for every HTTP request
  3. checking the token expiry before each request, and re-authenticating if necessary

Methods

__construct (callable $nextHandler, callable $tokenGenerator, Token $token = null)

No description

__invoke (RequestInterface $request, array $options) : mixed|void

This method is invoked before every HTTP request is sent to the API. When this happens, it checks to see whether a token is set and valid, and then sets the X-Auth-Token header for the HTTP request before letting it continue on its merry way.

Details

__construct(callable $nextHandler, callable $tokenGenerator, Token $token = null)

Parameters

$nextHandler callable
$tokenGenerator callable
$token Token

Example code

$authHandler->__construct($nextHandler, $tokenGenerator, $token);

__invoke(RequestInterface $request, array $options)

This method is invoked before every HTTP request is sent to the API. When this happens, it checks to see whether a token is set and valid, and then sets the X-Auth-Token header for the HTTP request before letting it continue on its merry way.

Parameters

$request RequestInterface
$options array

Return value

mixed|void

Example code

$response = $authHandler->__invoke($request, $options);