Componette

Componette

vojtech-dobes

vojtech-dobes / nette-multi-authenticator v2.0.0

Allows definition of multiple authentication ways with unified API (for Nette Framework)

download-cloud-line composer require vojtech-dobes/nette-multi-authenticator

For Nette Framework

Allows definition of multiple authentication ways with unified API (for Nette Framework)

License

New BSD

Dependencies

Nette 2.0 or newer

Installation

None, really :).

Usage

Write your authenticators, but don't make them implement Nette\Security\IAuthenticator. On the other hand, request Nette\Security\User service as dependency.

class CredentialsAuthenticator
{

    /** @var Nette\Security\User */
    private $user;
    
    public function __construct(Nette\Security\User $user)
    {
        $this->user = $user;
    }

}

Now write your login method. Be creative!

public function login($username, $password)
{
    // ... your logic
    
    $this->user->login(new Identity( ... ));
}

Register your authenticator as service:

services:
    - CredentialsAuthenticator

And you're done.

For authentication, you should use the specific authenticator:

class SignPresenter extends Nette\Application\UI\Presenter
{

    /** @var CredentialsAuthenticator @inject */
    public $credentialsAuthenticator;

    // ...
    
    public function processLoginForm($form)
    {
        $values = $form->getValues();
        $this->credentialsAuthenticator->login($values->username, $values->password);
    }

}

The point is: use normal dependencies and wrap Nette\Security\User in them, not the other way around.

  • v2.0.0 2.0.0 "Clean slate"

    You can have multiple authenticators without any additional code actually. Welcome this brand new architecture :).

  • v1.0.4 1.0.4 (welcome Nette 2.1)

    Possible to install with Nette 2.1 by Composer.

  • v1.0.3 1.0.3

    Authenticators listed in configuration are not autowired by default, which makes the whole addon more usable immediately after installing.

  • v1.0.2 1.0.2

    Now compatible with upcoming Nette 2.1.

    If you want to install Multi Authenticator via Composer to use it with Nette dev version, please use inline aliases.

bar-chart-fill

Statistics

download-cloud-fill
3412
star-fill
38
bug-fill
0
flashlight-fill
7.3y
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=5.3.2)
Componette Componette felix@nette.org