You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
<?php
|
|
|
|
namespace authkit2\Oidc\Authentication;
|
|
|
|
/**
|
|
* Abstract provider for signing/authenticating http requests
|
|
*/
|
|
abstract class Authentication
|
|
{
|
|
/**
|
|
* Authenticate the passed in HTTP request
|
|
*
|
|
* @param \GuzzleHttp\Psr7\Request $request request to authenticate
|
|
* @return \GuzzleHttp\Psr7\Request authenticated request
|
|
*/
|
|
public abstract function authenticate(\GuzzleHttp\Psr7\Request $request): \GuzzleHttp\Psr7\Request;
|
|
|
|
/**
|
|
* Wrap this provider up as a middleware appropriate for use directly with
|
|
* Guzzle's handler stack.
|
|
*
|
|
* @return callable
|
|
*/
|
|
public function getMiddleware(): callable
|
|
{
|
|
$auth = $this;
|
|
return function(callable $handler) use ($auth) {
|
|
return function(\Psr\Http\Message\RequestInterface $request, array $options) use ($handler, $auth) {
|
|
return $handler(
|
|
$auth->authenticate($request),
|
|
$options
|
|
);
|
|
};
|
|
};
|
|
}
|
|
|
|
public function getClient(array $options = []): \GuzzleHttp\Client
|
|
{
|
|
$stack = new \GuzzleHttp\HandlerStack();
|
|
$stack->setHandler(new \GuzzleHttp\Handler\CurlHandler());
|
|
$stack->push($this->getMiddleware());
|
|
return new \GuzzleHttp\Client(array_merge($options, ['handler' => $stack]));
|
|
}
|
|
}
|
|
|