PHPackages                             magicmaster0511/yii2-ldap-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. magicmaster0511/yii2-ldap-auth

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

magicmaster0511/yii2-ldap-auth
==============================

Simple library to handle auth over LDAP in Yii 2 applications.

1.4.1(1y ago)053MITPHPPHP &gt;= 8.3

Since Aug 10Pushed 1y agoCompare

[ Source](https://github.com/MaGiCmAsTeR0511/yii2-ldap-auth)[ Packagist](https://packagist.org/packages/magicmaster0511/yii2-ldap-auth)[ RSS](/packages/magicmaster0511-yii2-ldap-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

Yii2 LDAP Auth
==============

[](#yii2-ldap-auth)

Simple extension to handle auth over LDAP in Yii 2 applications.

**This extension intended for applications that rely *only* on LDAP authentication and does not support access tokens.**

Installation
============

[](#installation)

```
composer require "magicmaster05111/yii2-ldap-auth"
```

Example of configuration and a use case
=======================================

[](#example-of-configuration-and-a-use-case)

Considering [yii2-app-basic](https://github.com/yiisoft/yii2-app-basic):

### Configure the component in your configuration file and change user identity class

[](#configure-the-component-in-your-configuration-file-and-change-user-identity-class)

```
'components' => [
    ...
    'ldapAuth' => [
        'class' => '\stmswitcher\Yii2LdapAuth\LdapAuth',
        'host' => 'your-ldap-hostname',
        'baseDn' => 'dc=work,dc=group',
        'searchUserName' => '',
        'searchUserPassword' => '',

        // optional parameters and their default values
        'ldapVersion' => 3,             // LDAP version
        'protocol' => 'ldaps://',       // Protocol to use
        'followReferrals' => false,     // If connector should follow referrals
        'port' => 636,                  // Port to connect to
        'loginAttribute' => 'uid',      // Identifying user attribute to look up for
        'ldapObjectClass' => 'person',  // Class of user objects to look up for
        'timeout' => 10,                // Operation timeout, seconds
        'connectTimeout' => 5,          // Connect timeout, seconds
    ],
    ...

    'user' => [
        'identityClass' => '\stmswitcher\Yii2LdapAuth\Model\LdapUser',
    ],
    ...
]
```

### Update methods in LoginForm class

[](#update-methods-in-loginform-class)

```
use stmswitcher\Yii2LdapAuth\Model\LdapUser;

...

public function validatePassword($attribute, $params)
{
    if (!$this->hasErrors()) {
        $user = LdapUser::findIdentity($this->username);

        if (!$user || !Yii::$app->ldapAuth->authenticate($user->getDn(), $this->password)) {
            $this->addError($attribute, 'Incorrect username or password.');
        }
    }
}

...

public function login()
{
    if ($this->validate()) {
        return Yii::$app->user->login(
            LdapUser::findIdentity($this->username),
            $this->rememberMe
                ? 3600*24*30 : 0
        );
    }
    return false;
}
```

### Verify that user belongs to LDAP group

[](#verify-that-user-belongs-to-ldap-group)

If you need also need to check if user is a member of certain LDAP group, use one more parameter for the `authenticate` function:

```
Yii::$app->ldapAuth->authenticate($user->getDn(), $this->password, 'cn=auth-user-group')
```

Now you can login with LDAP credentials to your application.

### Using Access Control Filter

[](#using-access-control-filter)

If you want to use the Access Control Filter, you can use the LdapManager class as an authentication manager:

```
return [
    'components' => [
        'authManager' => [
            'class' => 'stmswitcher\Yii2LdapAuth\LdapManager',
        ],
    ],
];
```

Next, specify the list of groups that need to be granted access to actions:

```
public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::class,
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['group1', 'group2'],
                ],
            ],
        ],
    ];
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

6

Last Release

592d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad093eb93bd6324e385c6466e82f6781bef0ad8bbe7f898340b86b5d4badbcd3?d=identicon)[MaGiCmAsTeR0511](/maintainers/MaGiCmAsTeR0511)

---

Top Contributors

[![KurtHohenauer](https://avatars.githubusercontent.com/u/232852095?v=4)](https://github.com/KurtHohenauer "KurtHohenauer (11 commits)")[![glukinov](https://avatars.githubusercontent.com/u/93668835?v=4)](https://github.com/glukinov "glukinov (5 commits)")[![stmswitcher](https://avatars.githubusercontent.com/u/10289021?v=4)](https://github.com/stmswitcher "stmswitcher (3 commits)")

---

Tags

authyii2extensionldap

### Embed Badge

![Health badge](/badges/magicmaster0511-yii2-ldap-auth/health.svg)

```
[![Health](https://phpackages.com/badges/magicmaster0511-yii2-ldap-auth/health.svg)](https://phpackages.com/packages/magicmaster0511-yii2-ldap-auth)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

791.2M17](/packages/kartik-v-yii2-password)[chrmorandi/yii2-ldap

Ldap

1453.1k](/packages/chrmorandi-yii2-ldap)[kakadu-dev/yii2-jwt-auth

Extension provide JWT auth for Yii2

105.8k](/packages/kakadu-dev-yii2-jwt-auth)[yiichina/yii2-auth

Yii2 中使用第三方登录扩展，包括：微博，QQ，微信，百度等

191.1k2](/packages/yiichina-yii2-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
