surda/adldap2-nette

Adldap2 integration into Nette Framework

v2.0.2 2022-12-16 09:04 UTC

This package is auto-updated.

Last update: 2024-11-19 13:45:14 UTC


README

Build Status Licence Latest stable PHPStan

Installation

The recommended way to is via Composer:

composer require surda/adldap2-nette

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

extensions:
    adldap: Surda\Adldap\DI\AdldapExtension
    adldap.credentialsFactory: Surda\Adldap\DI\LdapCredentialsExtension

Minimal configuration

adldap:
    hosts: { 'corp-dc1.corp.acme.org', 'corp-dc2.corp.acme.org' }
    base_dn: 'dc=corp,dc=acme,dc=org'
    username: 'admin'
    password: 'password'

List of all configuration options:

adldap:
    # Mandatory configuration options
    hosts: { 'corp-dc1.corp.acme.org', 'corp-dc2.corp.acme.org' }
    base_dn: 'dc=corp,dc=acme,dc=org'
    username: 'admin'
    password: 'password'

    # Optional configuration options
    schema: \Adldap\Schemas\ActiveDirectory
    account_prefix: 'ACME-'
    account_suffix: '@@acme.org'
    port: 389
    follow_referrals: FALSE
    use_ssl: false
    use_tls: false
    version: 3
    timeout: 5

adldap.credentialsFactory:
  accountPrefix: ''
  accountSuffix: '@@ad.domain.com'

Usage

use Adldap\Adldap;
use Adldap\Auth\BindException;
use Adldap\Auth\PasswordRequiredException;
use Adldap\Auth\UsernameRequiredException;

class Foo
{
    public function __construct(private Adldap $adldap)
    {
    }

    public function auth(): bool
    {
        $provider = $this->adldap->connect();

        try {
            return $provider->auth()->attempt('username', 'password');
        }
        catch (BindException $e) {
        }
        catch (PasswordRequiredException $e) {
        }
        catch (UsernameRequiredException $e) {
        }
    }
}

More in the Adldap2 documentation.