Skip to content
Multi authenticator for Nette Framework
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpstan.neon

README.md

MultiAuthenticator

Build Status Licence Latest stable PHPStan

Installation

The recommended way to is via Composer:

composer require surda/multi-authenticator

After that you have to register extension in config.neon:

extensions:
    multiAuthenticator: Surda\MultiAuthenticator\DI\MultiAuthenticatorExtension

Minimal configuration

multiAuthenticator:
    authenticators:
        - MyLdapAuthenticator
        - MyDatabaseAuthenticator
        - ...

List of all configuration options:

multiAuthenticator:
    authenticators:
        - MyLdapAuthenticator
        - MyDatabaseAuthenticator
        - ...
    default: MyDefaultAuthenticator
    autowired: true # MultiAuthenticator::class

Using via MultiAuthenticator (default)

Autowired MultiAuthenticator class

try {
    $this->user->login($values->username, $values->password);
} catch (Nette\Security\AuthenticationException $e) {
    // ...
}

Using via resolver

use Surda\MultiAuthenticator\Resolver\AuthenticatorResolver;

/** @var AuthenticatorResolver */
private $resolver;

/**
 * @param AuthenticatorResolver $resolver
 */
public function __construct(AuthenticatorResolver $resolver)
{
    $this->resolver = $resolver;
}

try {
    $this->user->setAuthenticator($this->resolver->resolveByUsername('ad.domain.com\myusername'));
    // or
    $this->user->setAuthenticator($this->resolver->resolveByType('ldap'));
    
    try {
        $this->user->login($values->username, $values->password);
    } catch (Nette\Security\AuthenticationException $e) {
        // ...
    }
}
catch (AuthenticatorNotFoundException $e) {
    // ...
}
You can’t perform that action at this time.