PHPackages                             indigophp/guardian - 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. indigophp/guardian

Abandoned → [guardianphp/guardian](/?search=guardianphp%2Fguardian)ArchivedLibrary[Authentication &amp; Authorization](/categories/authentication)

indigophp/guardian
==================

Simple and flexible authentication framework

0157[4 issues](https://github.com/indigophp-archive/guardian/issues)PHP

Since Apr 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/indigophp-archive/guardian)[ Packagist](https://packagist.org/packages/indigophp/guardian)[ RSS](/packages/indigophp-guardian/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Guardian
========

[](#guardian)

[![Latest Version](https://camo.githubusercontent.com/52b2f3b0f5ed255b04ca7eca8efa4090c93297e6fdf62dbcee86097595701b38/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696e6469676f7068702f677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/indigophp/guardian/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/1af315cab9ff22d5d8e3b8be046a78cd572d2cce204c85394cb1291850160289/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696e6469676f7068702f677561726469616e2f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/indigophp/guardian)[![Code Coverage](https://camo.githubusercontent.com/f2ca37a836747f140724e9803bc3d42d15ceddc97df9d17aa6019c37b3addf9c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f696e6469676f7068702f677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/indigophp/guardian)[![Quality Score](https://camo.githubusercontent.com/6c1aa487066f44b1d7d63c863c75225873ccc74447f80abb95bb8d013106bed2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696e6469676f7068702f677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/indigophp/guardian)[![HHVM Status](https://camo.githubusercontent.com/61f0aa1d84a36ff0e689fee9a31f977dc1fbcc5491318e40b1d66ab2b814bd1f/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f696e6469676f7068702f677561726469616e2e7376673f7374796c653d666c61742d737175617265)](http://hhvm.h4cc.de/package/indigophp/guardian)[![Total Downloads](https://camo.githubusercontent.com/225f85b03296bdefe594840203fe22f92ff32fbc60d348d3225e325472d28851/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e6469676f7068702f677561726469616e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/indigophp/guardian)

**Simple and flexible authentication framework.**

Install
-------

[](#install)

Via Composer

```
$ composer require indigophp/guardian
```

Usage
-----

[](#usage)

This library provides an easy way to authenticate any entity with OR without persisting and calling it "login".

A simple login example:

```
use Indigo\Guardian\Identifier\InMemory;
use Indigo\Guardian\Authenticator\UserPassword;
use Indigo\Guardian\Hasher\Plaintext;
use Indigo\Guardian\SessionAuth;
use Indigo\Guardian\Session\Native;

$identifier = new InMemory([
    1 => [
        'username' => 'john.doe',
        'password' => 'secret',
        'name'     => 'John Doe',
    ],
]);

$authenticator = new UserPassword(new Plaintext);
$session = new Native;

$auth = new SessionAuth($identifier, $authenticator, $session);

// returns true to indicate success
$auth->login([
    'username' => 'john.doe',
    'password' => 'secret',
]);
```

Later, when login succeeds, check for the current login:

```
// returns true/false
$auth->check();

// returns the current caller
$caller = $auth->getCurrentCaller();
```

And logout at the end:

```
// returns true/false
$auth->logout();
```

### API Authentication

[](#api-authentication)

Since Guardian is an authentication library, you can easily use it to authenticate API requests without persistence. To achieve this, see the following simple authentication service:

```
use Indigo\Guardian\Identifier\InMemory;
use Indigo\Guardian\Authenticator\UserPassword;
use Indigo\Guardian\Hasher\Plaintext;
use Indigo\Guardian\RequestAuth;

$identifier = new InMemory([
    1 => [
        'username' => 'john.doe',
        'password' => 'secret',
        'name'     => 'John Doe',
    ],
]);

$authenticator = new UserPassword(new Plaintext);

$auth = new RequestAuth($identifier, $authenticator);

$subject = [
    'username' => 'john.doe',
    'password' => 'secret',
];

// returns true to indicate success
$auth->authenticate($subject);

// returns the caller object if identify succeeds
$caller = $auth->authenticateAndReturn($subject);
```

Testing
-------

[](#testing)

```
$ phpspec run
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Márk Sági-Kazár](https://github.com/sagikazarmark)
- [All Contributors](https://github.com/indigophp/guardian/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e4e105cea62b616d4cb376b08a849b6a428f646998537de150d16a8eb537b90?d=identicon)[mark.sagikazar](/maintainers/mark.sagikazar)

![](https://www.gravatar.com/avatar/1585b5a08e138e348f5b646231d0f16cb2eae06501fb9462bbc97a794d4de84a?d=identicon)[TamasBarta](/maintainers/TamasBarta)

---

Top Contributors

[![sagikazarmark](https://avatars.githubusercontent.com/u/1226384?v=4)](https://github.com/sagikazarmark "sagikazarmark (32 commits)")

### Embed Badge

![Health badge](/badges/indigophp-guardian/health.svg)

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M117](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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