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.7k2MITPHPPHP &gt;=7.1

Since Nov 21Pushed 10mo 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 3d 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

40

—

FairBetter than 88% of packages

Maintenance48

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

301d 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://www.gravatar.com/avatar/f7f49cbc31f2166f057acdcb3768366d6783ad6a8e5caf7e5990b21d8bbecf3d?d=identicon)[s-aebischer](/maintainers/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

[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[simplesamlphp/saml2

SAML2 PHP library from SimpleSAMLphp

30317.2M40](/packages/simplesamlphp-saml2)[facile-it/php-openid-client

OpenID (OIDC) Client

42592.7k7](/packages/facile-it-php-openid-client)[heptacom/shopware-platform-admin-open-auth

Shopware plugin to allow OAuth providers to provide admin logins

35133.7k](/packages/heptacom-shopware-platform-admin-open-auth)[ekapusta/oauth2-esia

Allows to authenticate in ESIA and get authenticated individual personal information.

73189.8k1](/packages/ekapusta-oauth2-esia)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5016.9k1](/packages/simplesamlphp-simplesamlphp-module-oidc)

PHPackages © 2026

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