Download the PHP package usmonaliyev/laravel-redis-auth without Composer
On this page you can find all versions of the php package usmonaliyev/laravel-redis-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download usmonaliyev/laravel-redis-auth
More information about usmonaliyev/laravel-redis-auth
Files in usmonaliyev/laravel-redis-auth
Package laravel-redis-auth
Short Description Laravel authorization and authentication with redis database.
License MIT
Informations about the package laravel-redis-auth
laravel-redis-auth
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
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
- PHP >= 7.4
- predis/predis
- Redis database
Installation
Install the package via Composer:
Publish
Publish the package configuration:
Usage
Update the .env
configuration to use the cache for authentication:
You must add Usmonaliyev\LaravelRedisAuth\Traits\RedisAuthentication
trait to you App/Models/User
class.
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.
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
.
You can protect your routes by adding the auth middleware to them:
There are configurations in redis-auth.php
in config
folder.
You can change them.
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
License
This package is open-source and released under the MIT License.