vperyod/auth-handler

PSR7 Aura\Auth Authentication Handler

0.3.1 2019-04-29 18:23 UTC

This package is auto-updated.

Last update: 2024-04-29 02:45:39 UTC


README

Aura\Auth Authentication middleware

Latest version Build Status Coverage Status Quality Score

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()
        ];
    }
}