/** * @test */ public function it_reauthenticates_requests() { $signer = $this->getMockBuilder(RequestSigner::class)->disableOriginalConstructor()->getMock(); $middleware = Middleware::reauthenticate($signer); $handler = $middleware(new MockHandler([])); $this->assertInstanceOf(ReauthenticateMiddleware::class, $handler); }
/** * Creates a Guzzle client for communicating with a Keystone service. * * @param Tenant $tenant The keystone tenant to authenticate with * @param array $config The client configuration * @param string $class Optionally override the Guzzle client class * * @throws RequestException When a new token could not be requested. * * @return ClientInterface */ public function createClient(Tenant $tenant, array $config = [], $class = null) { if (null === $class) { $class = $this->clientClass; } $pool = new TokenPool($tenant, $this->cache, $this->logger); $signer = new RequestSigner($pool); $stack = HandlerStack::create(); $stack->before('http_errors', Middleware::signRequest($signer), 'signer'); $stack->before('http_errors', Middleware::reauthenticate($signer), 'reauth'); return new $class(array_merge($config, ['handler' => $stack, 'token_pool' => $pool])); }