vperyod / auth-handler
PSR7 Aura\Auth Authentication Handler
0.3.1
2019-04-29 18:23 UTC
Requires
- php: >=7.2
- aura/auth: ^2.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^8.1
- zendframework/zend-diactoros: ~2.0
Suggests
- jnjxp/vk: For authentication domain
This package is auto-updated.
Last update: 2024-10-29 04:14:44 UTC
README
Aura\Auth Authentication middleware
Installation
composer require vperyod/auth-handler
Usage
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() ]; } }