PHPackages                             gyselroth/micro-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. gyselroth/micro-auth

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

gyselroth/micro-auth
====================

Authentication implementation including support for LDAP and OpenID-connet

v1.1.1(1y ago)02.8k2MITPHPPHP &gt;=7.1

Since Nov 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/gyselroth/micro-auth)[ Packagist](https://packagist.org/packages/gyselroth/micro-auth)[ Docs](http://www.github.com/gyselroth/micro-auth)[ RSS](/packages/gyselroth-micro-auth/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (8)Versions (28)Used By (0)

Lightweight authentication library
==================================

[](#lightweight-authentication-library)

[![Build Status](https://camo.githubusercontent.com/9bc339b858956e8f919c015c1ce29189cc840661e113e22071f9311054f81f7d/68747470733a2f2f7472617669732d63692e6f72672f677973656c726f74682f6d6963726f2d617574682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gyselroth/micro-auth)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/732fda839e944cb0beba681d2157df397be316b392174b8154a9c6748ed55c22/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f677973656c726f74682f6d6963726f2d617574682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gyselroth/micro-auth/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/8b8b16829ade2cca63c599150a8de922ad11786b9d7b5ed722aee74f40257f3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677973656c726f74682f6d6963726f2d617574682e737667)](https://packagist.org/packages/gyselroth/micro-auth)[![GitHub release](https://camo.githubusercontent.com/d0b64d0f12d3d8e770cc8e7bf3612ec9ddee01a9236a75dab8dc96275b309884/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f677973656c726f74682f6d6963726f2d617574682e737667)](https://github.com/gyselroth/micro-auth/releases)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/gyselroth/micro-auth/master/LICENSE)

Description
-----------

[](#description)

This is a lightweight authentication library. It is adapter based and comes with support for LDAP and OpenID-connect. It can handle multiple adapter of the same or different types. This library contains no storage mechanism. If you wish to store the authentication you need to store the identity object in your sessesion storage.

Requirements
------------

[](#requirements)

The library is only &gt;= PHP7.1 compatible.

Download
--------

[](#download)

The package is available at packagist:

To install the package via composer execute:

```
composer require gyselroth/micro-auth

```

Documentation
-------------

[](#documentation)

### Simple example usage

[](#simple-example-usage)

Create authentication instance and inject an LDAP and OpenID-connect adapter:

```
use Micro\Auth;

$logger = new \My\Psr\Logger()
$auth = new Auth\Auth(\Psr\Log\LoggerInterface $logger);
$auth->injectAdapter(new Auth\Adapter\Basic\Ldap(new Auth\Ldap([
    'uri' => 'ldap://myldap.local:398',
    'binddn' => 'cn=admin,dc=test,dc=com',
    'bindpw' => '1234',
    'basedn' => 'dc=test,dc=com',
    'tls' => true
]), $logger, [
    'account_filter' => '(&(objectClass=posixAccount)(uid=%s))'
]), 'my_ldap_server');

$auth->injectAdapter(new Auth\Adapter\Oidc([
    'provider_url' => 'https://accounts.google.com',
    'identity_attribute' => 'email'
], $logger), 'google_oidc_server');

if($auth->requireOne()) {
    $identity = $auth->getIdentity();
    printf('Hello %s', $identity->getIdentifier());
} else {
    //Authentication failed
}
```

### Define attribute map

[](#define-attribute-map)

So far so good but usually just authenticate is not enaugh, mostly you like to request user attributes of a given identity. Let us create an attribute map for our ldap server `my_ldap_server`.

```
use Micro\Auth;

$auth->injectAdapter(new Auth\Adapter\Basic\Ldap(new Auth\Ldap([
    'uri' => 'ldap://myldap.local:398',
    'binddn' => 'cn=admin,dc=test,dc=com',
    'bindpw' => '1234',
    'basedn' => 'dc=test,dc=com',
    'tls' => true
]), $logger, [
    'account_filter' => '(&(objectClass=posixAccount)(uid=%s))',
    'attribute_map' => [
        'firstname' => [
            'attr' => 'firstname',
            'type' => 'string',
        ],
        'lastname' => [
            'attr' => 'surname',
            'type' => 'string',
        ],
        'mail' => [
            'attr' => 'mail',
            'type' => 'string'
        ]
    ]
]), 'my_ldap_server');

if($auth->requireOne()) {
    $attributes = $auth->getIdentity()->getAttributes();
    var_dump($attributes);
} else {
    //Authentication failed
}
```

Given that, you can define an attribute map for each authentication adapter and map all attributes to the same attribute names you would like to use.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance41

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~111 days

Recently: every ~68 days

Total

26

Last Release

393d ago

Major Versions

v0.0.6 → v1.0.0-alpha12018-06-19

v0.0.8 → v1.0.0-alpha22018-11-21

v0.0.10 → v1.0.0-alpha42019-04-03

v0.0.11 → v1.0.0-alpha62022-01-31

v0.0.12 → v1.1.02024-10-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29914568?v=4)[Sandro Aebischer](/maintainers/s-aebischer)[@s-aebischer](https://github.com/s-aebischer)

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

---

Top Contributors

[![raffis](https://avatars.githubusercontent.com/u/2376735?v=4)](https://github.com/raffis "raffis (25 commits)")

---

Tags

authenticationldapopenid-connectphpmicroldapOpenID Connecthttp-basic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gyselroth-micro-auth/health.svg)

```
[![Health](https://phpackages.com/badges/gyselroth-micro-auth/health.svg)](https://phpackages.com/packages/gyselroth-micro-auth)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.4M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.9k20.0M1.8k](/packages/cakephp-cakephp)[google/auth

Google Auth Library for PHP

1.4k302.1M240](/packages/google-auth)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k20](/packages/tempest-framework)[simplesamlphp/saml2

SAML2 PHP library from SimpleSAMLphp

30418.3M44](/packages/simplesamlphp-saml2)

PHPackages © 2026

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