PHPackages                             hkt/expressive-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. hkt/expressive-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

hkt/expressive-auth
===================

Zend Expressive authentication via Aura.Auth

28PHP

Since Aug 2Pushed 9y ago1 watchersCompare

[ Source](https://github.com/harikt/expressive-auth)[ Packagist](https://packagist.org/packages/hkt/expressive-auth)[ RSS](/packages/hkt-expressive-auth/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

PSR-7 Authentication via Aura.Auth
==================================

[](#psr-7-authentication-via-auraauth)

Currently only works with Zend Expressive. If other PSR-7 based libraries / frameworks integrates two (the next PSR's according to my opinion) [TemplateRendererInterface](https://github.com/zendframework/zend-expressive-template) and [RouterInterface](https://github.com/zendframework/zend-expressive-router), this library will work for everyone.

\[Experimental Version\].

Some @todo

- Do we need to use some sort of event handling system? The idea is to trigger events once a user is logged-in/logout from the system.
- How can the error messages handled nicely. Currently there is only one `error` variable.
- Write some tests once things get finalized.

```
composer require htk/expressive-auth

```

Configuration
-------------

[](#configuration)

Currently supports only Aura.Di. You may want to add / configure for other dependency injection containers.

```
// In /config/container.php

class_alias('Aura\Di\ContainerConfig', 'Aura\Di\Config');

$configClasses = [
    // Aura.Auth Configuration
    Aura\Auth\_Config\Common::class,
    Hkt\ExpressiveAuth\Di\AuthConfig::class,

    // Modify Route accordingly

    Hkt\ExpressiveAuth\Di\RouteConfig::class,

    // more config classes ...
];
```

In your `App\Di\Config` you may want to add the adapter you are going to use. Please see [Aura.Auth](https://github.com/auraphp/Aura.Auth#adapters).

Example below is for `Aura\Auth\Adapter\PdoAdapter`.

```
// In your App\Di\Config define()

$di->set('aura/auth:adapter', $di->lazyNew('Aura\Auth\Adapter\PdoAdapter'));
$di->params['Aura\Auth\Adapter\PdoAdapter']['pdo'] = $di->lazyGet('Aura\Sql\ExtendedPdo');
$di->params['Aura\Auth\Verifier\PasswordVerifier'] = array(
    'algo' => PASSWORD_DEFAULT,
);
```

Routes
------

[](#routes)

The current login and logout routes are `/login` and `/logout` respectively. You are not limited to modify to your needs.

After logged in Redirect To
---------------------------

[](#after-logged-in-redirect-to)

Once the user is logged in, it redirects to a route named `hkt/expressive-auth:home`. You can register a route or modify via the `Di/Config`. It looks something like

```
// After logged in redirect user to route named `home`
$di->params['Hkt\ExpressiveAuth\Action\LoginAction']['redirectTo'] = 'home';

// After logged in redirect user to route named `login`
$di->params['Hkt\ExpressiveAuth\Action\LogoutAction']['redirectTo'] = 'login';
```

Templates
---------

[](#templates)

The love for templates differ for users and projects. You can choose anything that supports [zend-expressive-template](https://github.com/zendframework/zend-expressive-template)

In your expressive `/config/autoload/templates.global.php` file you can set the path to template as

```
    'templates' => [
        'paths' => [
            // ....
            'hkt/expressive-auth'   => ['templates/auth'],
        ]
    ]
```

For the sake of simplicity here is a `/templates/auth/login.phtml` template.

```
