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

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

golem/auth
==========

Simple authentication library

3.0.0(3y ago)02533MITPHPPHP 7.4.\*|8.\*

Since Oct 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/spekkionu/golem-auth)[ Packagist](https://packagist.org/packages/golem/auth)[ RSS](/packages/golem-auth/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (4)Used By (3)

Golem Auth
==========

[](#golem-auth)

[![Latest Stable Version](https://camo.githubusercontent.com/9182eda04b0e9b0699d9471dd3df75abee592877c967132003c7c01dde333847/68747470733a2f2f706f7365722e707567782e6f72672f676f6c656d2f617574682f762f737461626c652e706e67)](https://packagist.org/packages/golem/auth)[![Build Status](https://camo.githubusercontent.com/4a6ed8f8a54ed14aa6ebd6fff4ee5d71f9138804d2ee7ee96cb3b5f40b61cdad/68747470733a2f2f7472617669732d63692e6f72672f7370656b6b696f6e752f676f6c656d2d617574682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/spekkionu/golem-auth)[![Code Coverage](https://camo.githubusercontent.com/d6d06ba9ca7a52c657eee2cc2962d0f28a5b9b645811fa2d203c7ec70c2a3761/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7370656b6b696f6e752f676f6c656d2d617574682f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/spekkionu/golem-auth/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a1436ca59b4299862676e6bbc67cc92078e5d50732933ca6a75bce181db74f93/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7370656b6b696f6e752f676f6c656d2d617574682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/spekkionu/golem-auth/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/892c8deae343ab04ba3f26a8183c3134e02af79fc104bd6ed6f663807e20dc78/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f35346635346330642d393763372d346564642d616331322d6631613862626562613030662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/54f54c0d-97c7-4edd-ac12-f1a8bbeba00f)

Simple authentication storage library.

This library only handles the storage of authentication data. It does not handle the authentication itself or storage/retrieval of user data.

Install
-------

[](#install)

Via Composer

```
$ composer require golem/auth
```

Usage
-----

[](#usage)

You must have a user model that implements `Golem\Auth\Authenticatable`.

The `getAuthId` method must return a unique identifier for the user. This can be an auto-incrementing primary key, a uuid, a unique email address or username, or any other field that can be used to uniquely identify a user.

```
use Golem\Auth\Authenticatable;

class User implements Authenticatable
{
    public $id;
    public $name;
    public $email;

    public function getAuthId()
    {
        return $this->id;
    }
}
```

Your repository or database model must implement `Golem\Auth\UserRepository`.

The `findUserById` method must return the user object that implements `Golem\Auth\Authenticatable` for the given value of the field returned by `getAuthId`.

It should throw a RuntimeException if the user is not found.

```
class UserRepository implements \Golem\Auth\UserRepository
{
    public function findUserById($id)
    {
        // or whatever you need to do to pull a user record
        $data = $this->database->fetchRow('SELECT * from users WHERE id = ?', [$id]);
        if (!$data) {
            throw new \RuntimeException('User not found.');
        }
        return new User($data);
    }
}
```

You now can use the Golem Auth library.

```
// Use the native php session
session_start();
$storage = new \Golem\Auth\NativeSession();
// get an instance of your user repository however you need to
$userRepository = new UserRepository($database_connection);
$auth = new \Golem\Auth($storage, $userRepository);
```

### Logging in a User

[](#logging-in-a-user)

You must pull a user record and check the credentials yourself. This is not part of Golem Auth. I recommend using the [password\_hash](http://us3.php.net/manual/en/function.password-hash.php), and [password\_verify](http://us3.php.net/manual/en/function.password-verify.php) functions to check credentials.

```
// Should return a User instance that implements Golem\Auth\Authenticatable
$user = $userRepository->getByCredentials($email, $password);

// Store the user login
$auth->login($user);
```

### Checking for a logged in User

[](#checking-for-a-logged-in-user)

```
if ($auth->loggedIn()) {
  // The user is logged in
}

if (!$auth->loggedIn()) {
  // The user is not logged in
}
```

### Getting the user object for the currently logged in user

[](#getting-the-user-object-for-the-currently-logged-in-user)

```
// The first time this is called a fresh user record will be pulled from the UserRepository.
// Any further calls will return the existing record.
// If there is no logged in user this will return null.
// If the logged in user cannot be pulled a RuntimeException will be thrown.
$user = $auth->user();

// Returns just the user identifier
// This does not pull anything from the UserRepository
$id = $auth->getUserId();
```

### Logging out the user

[](#logging-out-the-user)

```
$auth->logout();
```

Testing
-------

[](#testing)

```
$ composer test
```

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~1154 days

Total

3

Last Release

1184d ago

Major Versions

1.0.0 → 2.0.02017-05-08

2.0.0 → 3.0.02023-02-15

PHP version history (2 changes)1.0.0PHP ~5.6|~7.0

3.0.0PHP 7.4.\*|8.\*

### Community

Maintainers

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

---

Top Contributors

[![jonbernardi](https://avatars.githubusercontent.com/u/38191?v=4)](https://github.com/jonbernardi "jonbernardi (15 commits)")[![spekkionu](https://avatars.githubusercontent.com/u/38191?v=4)](https://github.com/spekkionu "spekkionu (15 commits)")

---

Tags

authauthenticationgolem-authphp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  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.2M118](/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)
