PHPackages                             usmonaliyev/laravel-redis-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. usmonaliyev/laravel-redis-auth

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

usmonaliyev/laravel-redis-auth
==============================

Laravel authorization and authentication with redis database.

1.5.1(1y ago)72.5k—8.3%MITPHPPHP ^7.4|^8.1

Since May 18Pushed 1y ago2 watchersCompare

[ Source](https://github.com/usmonaliyev99/laravel-redis-auth)[ Packagist](https://packagist.org/packages/usmonaliyev/laravel-redis-auth)[ RSS](/packages/usmonaliyev-laravel-redis-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

laravel-redis-auth
==================

[](#laravel-redis-auth)

[![Packagist Dependency Version](https://camo.githubusercontent.com/b6d4523f36958d97eeb6a910026b22dbf70436fde7a65e079b9650f2be19a6d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f75736d6f6e616c697965762f6c61726176656c2d72656469732d617574682f706870)](https://camo.githubusercontent.com/b6d4523f36958d97eeb6a910026b22dbf70436fde7a65e079b9650f2be19a6d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f75736d6f6e616c697965762f6c61726176656c2d72656469732d617574682f706870)[![Total Downloads](https://camo.githubusercontent.com/13c469f0523ddb5b96b5cf414e4d5a421d646e9a9d1b9f0e4e5f468c084d5e06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f75736d6f6e616c697965762f6c61726176656c2d72656469732d617574682e737667)](https://camo.githubusercontent.com/13c469f0523ddb5b96b5cf414e4d5a421d646e9a9d1b9f0e4e5f468c084d5e06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f75736d6f6e616c697965762f6c61726176656c2d72656469732d617574682e737667)[![Latest Version on Packagist](https://camo.githubusercontent.com/fb6e7326bac9cd09faff0c42ccc9fd4393aa8581afed648dc76be4831e92ce52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f75736d6f6e616c697965762f6c61726176656c2d72656469732d617574682e737667)](https://camo.githubusercontent.com/fb6e7326bac9cd09faff0c42ccc9fd4393aa8581afed648dc76be4831e92ce52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f75736d6f6e616c697965762f6c61726176656c2d72656469732d617574682e737667)[![Packagist License](https://camo.githubusercontent.com/92e333728ced218a9986110748f0ea957b08d4371c8b9ec053295d42241a46d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f75736d6f6e616c697965762f6c61726176656c2d72656469732d61757468)](https://camo.githubusercontent.com/92e333728ced218a9986110748f0ea957b08d4371c8b9ec053295d42241a46d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f75736d6f6e616c697965762f6c61726176656c2d72656469732d61757468)

The Laravel Redis Auth Package is a Composer package that provides authentication functionality using a Redis database in Laravel applications. It offers a seamless integration with Laravel's authentication system while leveraging the speed and flexibility of Redis for storing user credentials.

Purpose
-------

[](#purpose)

I wanted to build microservices and I realized that I need a authentication service which can works with all microservices. Then I had created this package. If you have three microservices, you should install this package to your all of them and you should connect services to one Redis database. When client sends request to get new access token, one of your services creates access token and stores it to Redis database. When client sends request to other service with acces token, that service can check token from Redis database.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- predis/predis
- Redis database

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

[](#installation)

Install the package via Composer:

```
composer require usmonaliyev/laravel-redis-auth
```

Publish
-------

[](#publish)

Publish the package configuration:

```
php artisan vendor:publish --provider="Usmonaliyev\LaravelRedisAuth\RedisAuthServiceProvider"
```

Usage
-----

[](#usage)

Update the `.env` configuration to use the cache for authentication:

```
REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

REDIS_PREFIX=''
```

You must add `Usmonaliyev\LaravelRedisAuth\Traits\RedisAuthentication` trait to you `App/Models/User` class.

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Usmonaliyev\LaravelRedisAuth\Traits\RedisAuthentication;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, RedisAuthentication;

    ...
```

After that you can create access token by `createAuthToken` function of `App/Models/User` class. You can create token with abilities. The packge stored all tokens with abilities in Redis database.

```
$user = User::query()
    ->where('email', $request->string('email'))
    ->first();

$accessToken = $user->createAuthToken([
    'users.add',
    'users.show',
    'users.delete',
]);
```

You can check token's ability with `check` function of `App/Models/User` class in your Controllers. If user does not have a ability, `check` function throw `Illuminate/Http/Exceptions/HttpResponseException`.

```
Auth::user()->check('users.add', "If you want to change error message!");

OR

auth()->user()->check('messages.show');
```

You can protect your routes by adding the auth middleware to them:

```
Route::middleware('redis-auth')->group(function () {
    // Protected routes
});
```

There are configurations in `redis-auth.php` in `config` folder. You can change them.

```
    /**
     * Name of redis connection.
     *
     * Note that this name is listed in the redis section of your config/database.php
     */
    'connection' => env('REDIS_AUTH_CONNECTION', 'default'),

    /**
     * Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..)
     * See hash_algos for a list of supported algorithms.
     */
    'algo' => env('REDIS_AUTH_ALGO', 'sha256'),

    /**
     * Secret key for creating a new token
     */
    'secret_key' => env('REDIS_AUTH_SECRET_KEY', 'laravel-redis-auth-secret-key'),

    /**
     * token_ttl represents the Token Time To Live, which defines the lifespan or expiration time of a token.
     */
    'token_ttl' => env('REDIS_AUTH_TOKEN_TTL', 3600 * 24),

    /**
     */
    'unauthorized_message' => env('UNAUTHORIZED_MESSAGE', 'Unauthorized...'),
```

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

[](#contributing)

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License
-------

[](#license)

This package is open-source and released under the MIT License.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

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

Recently: every ~118 days

Total

11

Last Release

615d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62ad097b3a2c1c7fba629ae280b33a9bcb12caf5dab6846737a7703046c5bad4?d=identicon)[usmonaliyev99](/maintainers/usmonaliyev99)

---

Top Contributors

[![usmonaliyev99](https://avatars.githubusercontent.com/u/63544323?v=4)](https://github.com/usmonaliyev99 "usmonaliyev99 (53 commits)")

---

Tags

laravelauthredis

### Embed Badge

![Health badge](/badges/usmonaliyev-laravel-redis-auth/health.svg)

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

###  Alternatives

[orchestra/auth

Auth Component for Orchestra Platform

24108.5k3](/packages/orchestra-auth)[codebot/entrust

This package provides a flexible way to add Role-based Permissions to Laravel

1596.6k](/packages/codebot-entrust)[ingria/laravel-x509-auth

Laravel 5 Client Certificate auth middleware

375.6k](/packages/ingria-laravel-x509-auth)[setiawanhu/sanctum-auth

Laravel package for generating user authentication feature using Laravel Sanctum

132.8k](/packages/setiawanhu-sanctum-auth)

PHPackages © 2026

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