PHPackages                             dotkernel/dot-authentication-service - 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. dotkernel/dot-authentication-service

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

dotkernel/dot-authentication-service
====================================

DotKernel authentication service component based on laminas-authentication

2.9.2(2y ago)22.3k↓50%2[1 issues](https://github.com/dotkernel/dot-authentication-service/issues)MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Mar 8Pushed 1y agoCompare

[ Source](https://github.com/dotkernel/dot-authentication-service)[ Packagist](https://packagist.org/packages/dotkernel/dot-authentication-service)[ RSS](/packages/dotkernel-dot-authentication-service/feed)WikiDiscussions 2.9-PHP-8.1 Synced 1mo ago

READMEChangelog (9)Dependencies (10)Versions (12)Used By (0)

Important

dot-authentication-service is a wrapper on top of [laminas/laminas-authentication](https://github.com/laminas/laminas-authentication)

[![Dynamic JSON Badge](https://camo.githubusercontent.com/b3155745b142f95710d2d8f6876e9b484d8074978e31859ec67395ba021f3c70/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532466170692e6769746875622e636f6d2532467265706f732532466c616d696e61732532466c616d696e61732d61757468656e7469636174696f6e25324670726f7065727469657325324676616c7565732671756572793d253234253542253346282534302e70726f70657274795f6e616d652533442533442532326d61696e74656e616e63652d6d6f6465253232292535442e76616c7565266c6162656c3d4d61696e74656e616e63652532304d6f6465)](https://camo.githubusercontent.com/b3155745b142f95710d2d8f6876e9b484d8074978e31859ec67395ba021f3c70/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d68747470732533412532462532466170692e6769746875622e636f6d2532467265706f732532466c616d696e61732532466c616d696e61732d61757468656e7469636174696f6e25324670726f7065727469657325324676616c7565732671756572793d253234253542253346282534302e70726f70657274795f6e616d652533442533442532326d61696e74656e616e63652d6d6f6465253232292535442e76616c7565266c6162656c3d4d61696e74656e616e63652532304d6f6465)

Caution

Security-Only Maintenance Mode
------------------------------

[](#security-only-maintenance-mode)

This package is considered feature-complete, and is now in **security-only** maintenance mode.

[![OSS Lifecycle](https://camo.githubusercontent.com/6baa973cbaca9ec7af3856a62436144db21081b922fff7efd88118336c96ebba/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c652f646f746b65726e656c2f646f742d61757468656e7469636174696f6e2d73657276696365)](https://camo.githubusercontent.com/6baa973cbaca9ec7af3856a62436144db21081b922fff7efd88118336c96ebba/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c652f646f746b65726e656c2f646f742d61757468656e7469636174696f6e2d73657276696365)[![GitHub license](https://camo.githubusercontent.com/1622c282d623051499bb37fa89c5df7bb005d32672240cc623bc3eab6cf5226f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646f746b65726e656c2f646f742d61757468656e7469636174696f6e2d73657276696365)](https://github.com/dotkernel/dot-authentication-service/blob/2.0.2/LICENSE.md)[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/cce4a875775afa23fc04fa3e8897a69bd4606816c182492c78a56a954d6b76fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d61757468656e7469636174696f6e2d736572766963652f322e392e32)](https://camo.githubusercontent.com/cce4a875775afa23fc04fa3e8897a69bd4606816c182492c78a56a954d6b76fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d61757468656e7469636174696f6e2d736572766963652f322e392e32)

dot-authentication-service
==========================

[](#dot-authentication-service)

Concrete authentication service implementation of `\Dot\Authentication\AuthenticationInterface` built using [laminas-authentication](https://github.com/laminas/laminas-authentication) authentication and storage adapters. We advise you to have a quick look at how laminas authentication works, by visiting the [documentation](https://docs.laminas.dev/laminas-authentication/)

Installation
------------

[](#installation)

Run the following command in your project directory

```
$ composer require dotkernel/dot-authentication-service
```

Add the `ConfigProvider` class to your configuration aggregate, to register the default services.

Usage
-----

[](#usage)

You'll usually inject the authentication service into your classes and use its methods, as described by its interface at [dot-authentication](https://github.com/dotkernel/dot-authentication)

```
//...

public function __construct(AuthenticationInterface $authentication)
{
    $this->authentication = $authentication;
}

//...

public function someMethod()
{
    if($this->authentication->hasIdentity()) {
        //do something
    }
}
```

When creating the authentication service, you'll have to provide an authentication AdapterInterface and a StorageInterface.

We already provide some default implementations of authentication adapters and storage adapters, with the possibility to write your custom ones.

We also provide a convenient factory class that configures an authentication service based on configuration. Just merge the package's `ConfigProvider` output to your application config in order to register all the required dependencies.

Authentication adapters
-----------------------

[](#authentication-adapters)

Used by the authentication service to check the credentials against some backend. Can be easily exchanged with various implementations depending on the authentication type or backend type. An `\Dot\Authentication\Adapter\AdapterInterface` is provided which must be implemented by all adapters. Also, adapters should be registered in the `\Dot\Authentication\Adapter\AdapterPluginManager` service. More on this in the writing custom adapters section.

The AdapterInterface defines the following methods

```
public function prepare(ServerRequestInterface $request);
```

- called internally by the authentication service, just before the authentication operation, in order to give the adapter a chance to prepare itself, by extracting the credentials from the request, in its specific manner.

```
public function authenticate(): AuthenticationResult;
```

- checks the credentials extracted from the previous step, against some backend. Should return an `\Dot\Authentication\AuthenticationResult`

```
public function challenge(): ResponseInterface;
```

This method is optional, it depends on the authentication type if a challenge response is required. It should return a ResponseInterface with status code 401 and a WWW-Authenticate header to indicate authentication is required.

### HttpAdapter

[](#httpadapter)

This adapter provides HTTP basic and digest authentication. It is built around the laminas-authentication http adapter class. It actually wraps the laminas authentication http adapter, which can be configured by sending in the $config parameter as described by the laminas-authentication official documentation. We'll describe later how to configure an authentication service with such an adapter.

When authenticating, this adapter extracts the credentials from the request's `Authorization` header.

### CallbackCheckAdapter

[](#callbackcheckadapter)

Use to authenticate request against a MySQL backend. It is called so, because it accepts a callback as one of its parameters, which is called to check the password according to specific needs(md5, bcrypt etc.) It also wraps a laminas-authentication adapter with the same name, so much of its initialization is linked to that adapter. We'll describe later how to configure such an adapter.

This adapter requires that before calling the authentication service's authenticate method, you should manually extract the credentials from your request(POST) and initialize a `DbCredentials` class with it. It does not make assumptions on where the credentials should be in the request. It searches for a specific attribute instead, which you should add before authenticating. After extracting the credentials into a `DbCredentials` class, set this as a $request attribute at key `DbCredentials::class`.

```
$request = $request->withAttribute(DbCredentials::class, $dbCredentials);
```

##### Identity prototype and hydrator

[](#identity-prototype-and-hydrator)

Both these adapters require an identity prototype object and an optional hydrator class(ClassMethods by default) When successfully authenticating, it will hydrate the prototype with the user data and return it inside the `AuthenticationResult`.

Storage adapters
----------------

[](#storage-adapters)

Used by the authentication service to store the authenticated identity in some kind of persistent storage. All storage adapters must implement the `\Dot\Authentication\Storage\StorageInterface` interface. This interface extends the `\Laminas\Authentication\Storage\StorageInterface`. No additional interface methods are defined for now.

Also, storage adapters should be registered in the `\Dot\Authentication\Storage\StoragePluginManager`.

### SessionStorage

[](#sessionstorage)

It extends the `Laminas\Authentication\Storage\Session` class, providing the same functionality, with the only difference that on each write call, it will regenerate the session id. This is to prevent session fixation attacks, we renew the session id when user sign in. You can find more details on this storage adapter in laminas-authentication official documentation. We'll also give you an example in the following documentation on how to configure such an adapter.

### NonPersistenStorage

[](#nonpersistenstorage)

It extends the `Laminas\Authentication\Storage\NonPersistent` class. As its name suggests, it does not store the identity persistently. It will be lost after script finishes running. Useful for API implementations, where authentication is stateless.

Configuring an AuthenticationService
------------------------------------

[](#configuring-an-authenticationservice)

First of all, make sure you merge this package's `ConfigProvider` output to your application's config. This will add all necessary dependencies to your application, including the convenient factories. Create a separate config file in your `config/autoload` directory, call it authentication.global.php for example.

##### authentication.global.php

[](#authenticationglobalphp)

```
return [
    'dot_authentication' => [
        'adapter' => [
            'type' => 'CallbackCheck',
            'options' => [
                // laminas db adapter service name
                'adapter' => 'database service name',

                'identity_prototype' => '\You\Identity\Class\Implementing\IdentityInterface',
                'identity_hydrator' => '\Hydrator\Class\Implementing\HydratorInterface',

                // your user table name
                'table' => 'user table name',

                // what user fields should use for authentication(db fields)
                'identity_columns' => ['username', 'email'],

                // name of the password db field
                'credential_column' => 'password'

                // we recommend using a service name or class name instead of closures
                // the below closure is just an example, to show you the callable signature
                // 'callback_check' => function($hash_passwd, $password) {
                //    return $hash_passwd === md5($password);
                // }
            ],
        ],

        //storage specific options, example below, for session storage
        'storage' => [
            'type' => 'Session',
            'options' => [
                //session namespace
                'namespace' => 'dot_auth',

                //what session member to use
                'member' => 'storage'
            ],
        ],

        'adapter_manager' => [
            //register custom adapters here, like you would do in a normal container
        ],

        'storage_manager' => [
            //register custom storage adapters
        ],

        'resolver_manager' => [
            //define custom http authentication resolvers here
        ],
    ]
];
```

To define a http basic adapter you can define a configuration as below:

```
    'adapter' => [
        'type' => 'Http',
        'options' => [
            'identity_prototype' => '\You\Identity\Class\Implementing\IdentityInterface',
            'identity_hydrator' => 'Hydrator\Class\Implementing\HydratorInterface',

            'config' => [
                'accept_schemes' => 'basic',
                'realm' => 'api',
            ],

            'basic_resolver' => [
                'name' => 'FileResolver',
                'options' => [
                    'path' => 'path/to/.httpasswd',
                ],
            ],

            'digest_resolver' => [],
        ],
    ],
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 61% 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 ~257 days

Recently: every ~167 days

Total

11

Last Release

787d ago

Major Versions

0.2.0 → 1.0.02018-04-13

1.0.0 → v2.0.02020-01-30

PHP version history (5 changes)0.1.0PHP ^7.1

v2.0.0PHP ^7.2

2.1.x-devPHP ^7.4 || ~8.0.0 || ~8.1.0

2.0.x-devPHP ~8.0.0 || ~8.1.0 || ~8.2.0

2.9.2PHP ~8.1.0 || ~8.2.0 || ~8.3.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1156873?v=4)[Dotkernel](/maintainers/dotkernel)[@dotkernel](https://github.com/dotkernel)

---

Top Contributors

[![n3vrax](https://avatars.githubusercontent.com/u/5805542?v=4)](https://github.com/n3vrax "n3vrax (36 commits)")[![arhimede](https://avatars.githubusercontent.com/u/22009710?v=4)](https://github.com/arhimede "arhimede (9 commits)")[![claurospace](https://avatars.githubusercontent.com/u/224870609?v=4)](https://github.com/claurospace "claurospace (4 commits)")[![PopNatanael](https://avatars.githubusercontent.com/u/56395369?v=4)](https://github.com/PopNatanael "PopNatanael (3 commits)")[![gabidj](https://avatars.githubusercontent.com/u/3998573?v=4)](https://github.com/gabidj "gabidj (2 commits)")[![pinclau](https://avatars.githubusercontent.com/u/24491812?v=4)](https://github.com/pinclau "pinclau (2 commits)")[![SergiuBota1](https://avatars.githubusercontent.com/u/50962867?v=4)](https://github.com/SergiuBota1 "SergiuBota1 (2 commits)")[![bidi47](https://avatars.githubusercontent.com/u/27284979?v=4)](https://github.com/bidi47 "bidi47 (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dotkernel-dot-authentication-service/health.svg)

```
[![Health](https://phpackages.com/badges/dotkernel-dot-authentication-service/health.svg)](https://phpackages.com/packages/dotkernel-dot-authentication-service)
```

PHPackages © 2026

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