PHPackages                             elgibor-solution/laravel-authentication - 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. elgibor-solution/laravel-authentication

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

elgibor-solution/laravel-authentication
=======================================

A standalone authentication package using Laravel Passport and Spatie Permission.

v1.0.5(yesterday)03↑2900%MITPHPPHP ^8.3

Since Jun 8Pushed yesterdayCompare

[ Source](https://github.com/elgiborsolution/laravel-auth)[ Packagist](https://packagist.org/packages/elgibor-solution/laravel-authentication)[ RSS](/packages/elgibor-solution-laravel-authentication/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (2)Versions (8)Used By (0)

Elgibor Solution Laravel Authentication
=======================================

[](#elgibor-solution-laravel-authentication)

Enterprise-grade, multi-tenant ready authentication and authorization engine for Laravel.

Build secure, scalable API authentication processes with built-in role &amp; permission management, seamless `stancl/tenancy` integration, and automated setup — right out of the box.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Multi-Tenancy](#multi-tenancy)
- [Quick Start](#quick-start)
    - [1. Update Your User Model](#1-update-your-user-model)
    - [2. Authenticate](#2-authenticate)
    - [3. Fetch User Profile](#3-fetch-user-profile)
    - [4. Manage Roles &amp; Permissions](#4-manage-roles--permissions)
- [API Reference](#api-reference)
    - [Public Authentication Routes](#public-authentication-routes)
    - [Authorization Admin Routes](#authorization-admin-routes)

---

Features
--------

[](#features)

CategoryCapability**Authentication Engine**Robust API token generation and validation powered by Laravel Passport.**Role &amp; Permission**Built-in custom roles and permissions management (No need for Spatie).**Multi-Tenant**Shared-database or Database-per-tenant architectures natively supported via `stancl/tenancy`.**Automated Setup**1-click installation via Artisan command to scaffold migrations, keys, and configs.**Standardized API**Consistent HTTP status codes (200, 422, 401) wrapped in standard JSON formats.**Extensible Relations**Eager-load dynamic relationships (e.g., profiles, agency data) automatically upon fetching `/me`.---

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

[](#requirements)

- PHP ≥ 8.3
- Laravel 11.x or 12.x
- Database MySQL 8+ or PostgreSQL 14+

---

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

[](#installation)

### 1. Add the Package

[](#1-add-the-package)

Run the following command in your main project terminal to download the package:

```
composer require elgibor-solution/laravel-authentication
```

### 2. Automated Setup (Highly Recommended)

[](#2-automated-setup-highly-recommended)

Instead of configuring migrations and settings manually, run this automation command:

```
php artisan elgibor-auth:install
```

**The wizard will automatically:**

1. Publish all migration files (`roles`, `permissions` tables, etc.).
2. Ask if you are using `stancl/tenancy`. (If yes, it smartly moves migrations to the `tenant/` directory and generates keys securely).
3. Install Passport encryption keys (`php artisan passport:install` or `passport:keys`).
4. Update your `config/auth.php` file by injecting the `api` guard.
5. Automatically append the necessary traits into your project's `app/Models/User.php` model.

### 3. Publish Configuration (Optional)

[](#3-publish-configuration-optional)

To customize the flexibility of this package, publish the configuration file to your application's root directory:

```
php artisan vendor:publish --tag=authentication-config
```

This publishes `config/authentication.php` where you can customize all settings.

---

Configuration
-------------

[](#configuration)

The full configuration lives in `config/authentication.php`. Below are the most important sections:

```
// config/authentication.php
return [
    // Base URL prefix for all authentication endpoints
    'prefix' => 'api/auth',

    // Core middleware required for the package to function
    'middleware' => ['api', 'tenant'],

    // Require extra fields during login (e.g., 'tenant_id' for single-db tenancy)
    'login_extra_fields' => [],

    // Automatically eager-load relationships when calling the `/me` endpoint
    'load_relations' => ['profile', 'agency'],
];
```

---

Multi-Tenancy
-------------

[](#multi-tenancy)

This package is designed to work seamlessly with `stancl/tenancy` for database-per-tenant isolation.

### Automated Integration

[](#automated-integration)

If you run `php artisan elgibor-auth:install` and select **"Yes"** for `stancl/tenancy`:

- The package will automatically move `oauth_*` migrations into `database/migrations/tenant/` (roles and permissions migrations remain in the central database).
- It will generate central Passport keys without forcing client creation on the central DB.

### 1. Register Tenant Middleware

[](#1-register-tenant-middleware)

In Laravel 11, you must ensure the tenant *middleware* is registered in your application. Open your project's `bootstrap/app.php` file and add the alias:

```
->withMiddleware(function (Middleware $middleware): void {
    $middleware->alias([
        'tenant' => \Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class,
    ]);
})
```

### 2. Configure Package Middleware

[](#2-configure-package-middleware)

Ensure the `tenant` middleware is injected into the package's configuration:

```
// config/authentication.php
'middleware' => ['api', 'tenant'],
```

### 3. Tenant Client Generation

[](#3-tenant-client-generation)

Since the database is isolated, you must create a Personal Access Client inside each newly created tenant:

```
php artisan tenants:run passport:client --personal
```

---

Quick Start
-----------

[](#quick-start)

### 1. Update Your User Model

[](#1-update-your-user-model)

Ensure the `User` Model in your project uses the traits provided by the package (this is done automatically if you used the install command):

```
use ElgiborSolution\Authentication\Traits\HasCustomRole;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable {
    use HasApiTokens, HasCustomRole;
}
```

### 2. Authenticate

[](#2-authenticate)

Submit credentials to retrieve your access token:

```
curl -X POST http://your-app/api/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@example.com",
    "password": "password123"
  }'
```

### 3. Fetch User Profile

[](#3-fetch-user-profile)

Retrieve the authenticated user's profile, including their flattened permissions array and active tenant object:

```
curl http://your-app/api/auth/me \
  -H "Authorization: Bearer "
```

### 4. Manage Roles &amp; Permissions

[](#4-manage-roles--permissions)

Create a new role with assigned permissions:

```
curl -X POST http://your-app/api/auth/roles \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{
    "role_name": "Manager",
    "role_description": "Store manager",
    "permissions": [1, 2, 5]
  }'
```

---

API Reference
-------------

[](#api-reference)

### Public Authentication Routes

[](#public-authentication-routes)

The login route is public and has '/auth' stripped from the prefix.

MethodEndpointDescriptionRequest Body**POST**`/api/login`Authenticate user and issue token`email`, `password`, + `login_extra_fields`### Protected Authentication Routes

[](#protected-authentication-routes)

These routes require the `auth:api` middleware and are prefixed with `/api/auth`.

MethodEndpointDescriptionRequest Body**GET**`/api/auth/me`Get current user profile (with roles/tenant)— *(Requires Authorization Header)***POST**`/api/auth/logout`Revoke the current access token— *(Requires Authorization Header)*### Authorization Admin Routes

[](#authorization-admin-routes)

All routes require the `auth:api` middleware.

MethodEndpointDescription**GET**`/roles`List all roles (paginated and cached)**POST**`/roles`Create a new role with specific permissions**GET**`/roles/{id}`Show specific role details**PUT**`/roles/{id}`Update an existing role**DELETE**`/roles/{id}`Delete a role (if not protected)**GET**`/permissions`List all available permissions**PATCH**`/permissions/{id}/toggle-status`Toggle permission status (Active 1 / Inactive 9)

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance100

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.3% 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 ~0 days

Total

6

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5470172?v=4)[esolution](/maintainers/esolution)[@esolution](https://github.com/esolution)

---

Top Contributors

[![rifqiazib](https://avatars.githubusercontent.com/u/73076322?v=4)](https://github.com/rifqiazib "rifqiazib (8 commits)")[![zakii-213](https://avatars.githubusercontent.com/u/202097688?v=4)](https://github.com/zakii-213 "zakii-213 (6 commits)")[![elgibor-solution](https://avatars.githubusercontent.com/u/783039?v=4)](https://github.com/elgibor-solution "elgibor-solution (1 commits)")

### Embed Badge

![Health badge](/badges/elgibor-solution-laravel-authentication/health.svg)

```
[![Health](https://phpackages.com/badges/elgibor-solution-laravel-authentication/health.svg)](https://phpackages.com/packages/elgibor-solution-laravel-authentication)
```

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.1k2.2k](/packages/unopim-unopim)[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

58403.6k8](/packages/jeremy379-laravel-openid-connect)

PHPackages © 2026

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