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

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

gobline/auth
============

Authentication component

v2.0.1(10y ago)21402BSD-3-ClausePHPPHP &gt;=5.6.0

Since Nov 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gobline/auth)[ Packagist](https://packagist.org/packages/gobline/auth)[ Docs](https://github.com/gobline)[ RSS](/packages/gobline-auth/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (2)

Authentication component
========================

[](#authentication-component)

Most oftenly, your server needs a way to identify the user making the current request. The authentication component provides a means for representing the user making the request and for authenticating this user against a DB or other datasource.

- the `CurrentUserInterface` allows the server to **identify** the user making the current request.
- the `AuthenticatorInterface` allows the server to **authenticate** the user with provided credentials.

Usage
-----

[](#usage)

In order to authenticate a user, you will first need to create a `CurrentUser` object.

```
$user = new Gobline\Auth\CurrentUser();
```

Once we have a user, we can authenticate the latter using an adapter implementing `AuthenticatorInterface`. One implementation is already provided, authenticating the user against a database: `DbAuthenticator`.

Firstly, we will have to set up the adapter. The `DbAuthenticator` requires a [PDO](http://php.net/manual/en/class.pdo.php) instance and an instance of `TableMetadata` wrapping some metadata about the DB table we are authenticating against.

```
use Gobline\Auth\Authenticator\Db\TableMetadata;
use Gobline\Auth\Authenticator\Db\DbAuthenticator;

$authenticator = new DbAuthenticator($pdo, new TableMetadata('users'));
```

By default, `TableMetadata` assumes that

- the column `id` contains the **id** of the user
- the column `email` contains the **login** of the user
- the column `password` contains the **password** of the user
- the password encryption is **bcrypt** (possible values are: *bcrypt*, *md5*, *sha1* or *clear*)

Customize these metadata for your database.

```
use Gobline\Auth\Authenticator\Db\TableMetadata;
use Gobline\Auth\Authenticator\Db\DbAuthenticator;

$metadata = new TableMetadata('users');
$metadata
    ->setColumnId('user_id')
    ->setColumnLogin('user_email')
    ->setColumnRole('user_type')
    ->setColumnPassword('user_password')
    ->setPasswordEncryption('md5');

$authenticator = new DbAuthenticator($pdo, $metadata);
```

*You will also notice that besides the id, login and password, it is possible to specify a column containing the role (or group, type) of the user. This is especially useful when combining the authentication component with an ACL component (which is usually the case).*

Now that we have set up our adapter, it's time to authenticate the user.

```
$authenticator->setIdentity('mdecaffmeyer@gmail.com');
$authenticator->setCredential('123456');

$user->isAuthenticated(); // returns false

if ($authenticator->authenticate($user)) {
	echo $user->getId(); // prints the user id from DB

	$user->isAuthenticated(); // returns true
}
```

**The authenticator sets the id and the login of the user.**It can additionally add the user's role (for ACL) and other column data.

**An authenticated user is a user whose id is not null.**

### Persist the user's data among requests

[](#persist-the-users-data-among-requests)

While the above works perfectly for the first request, the user's data will be lost on subsequent requests. One way to achieve persistence is to store the user data in session. `Gobline\Auth\Persistence\CurrentUser` acts like a decorator over `Gobline\Auth\CurrentUser` (or any `Gobline\Auth\CurrentUserInterface` implementation), allowing to persist the data in session.

```
$user = new Gobline\Auth\CurrentUser();
$user = new Gobline\Auth\Persistence\CurrentUser($user);
```

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

[](#installation)

You can install Gobline Auth using the dependency management tool [Composer](https://getcomposer.org/). Run the *require* command to resolve and download the dependencies:

```
composer require gobline/auth

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

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 ~130 days

Total

4

Last Release

3858d ago

Major Versions

v1.0.1 → v2.0.02015-12-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/1564a230fe2f5125b0504cf6b6fe1e829face1a5d20ec663b3b8d22843312c7d?d=identicon)[mdecaffmeyer](/maintainers/mdecaffmeyer)

---

Tags

authAuthenticationauthenticatorgobline

### Embed Badge

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

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

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k50.9M364](/packages/tymon-jwt-auth)[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.7k143.0M274](/packages/league-oauth2-server)[robthree/twofactorauth

Two Factor Authentication

1.2k11.6M86](/packages/robthree-twofactorauth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

83910.6M60](/packages/php-open-source-saver-jwt-auth)[auth0/auth0-php

PHP SDK for Auth0 Authentication and Management APIs.

40921.3M85](/packages/auth0-auth0-php)[kreait/firebase-tokens

A library to work with Firebase tokens

23943.8M18](/packages/kreait-firebase-tokens)

PHPackages © 2026

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