Aura\Auth Authentication middleware
composer require vperyod/auth-handler
See Aura\Auth documentation.
// Create handler with Auth and ResumeService instance
$handler = new Vperyod\AuthHandler\AuthHandler($auth, $resume);
// Optionally set the `AuthAttribute`, the name of the attribute on which to
// store the `AuthAttribute` in the `Request`. Defaults to 'aura/auth:auth'
$handler->setAuthAttribute('auth');
// Add to your middleware stack, radar, relay, etc.
$stack->middleware($handler);
// Subsequest dealings with `Request` will have the `Auth` instance available at
// the previous specified atribute
$auth = $request->getAttribute('auth');
// The `AuthRequestAwareTrait` should make dealings easier.
//
// Have all your objects that deal with the auth attribute on the request use
// the `AuthRequestAwareTrait` and have your DI container use the setter, so that
// they all know where the auth object is stored.
class MyMiddleware
{
use \Vperyod\AuthHandler\AuthRequestAwareTrait;
public function __invoke($request, $response, $next)
{
$auth = $this->getAuth($request);
$status = $this->getAuthStatus($request);
$isValid = $this->isAuthValid($request);
// ...
return $next($request, $response);
}
}
class MyInputExtractor
{
use \Vperyod\AuthHandler\AuthRequestAwareTrait;
public funciton __invoke($request)
{
return [
'auth' => $this->getAuth($request),
'data' => $request->getParsedBody()
];
}
}