PHPackages                             sepehr-mohseni/laratenauth - 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. sepehr-mohseni/laratenauth

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

sepehr-mohseni/laratenauth
==========================

Laravel multi-tenant authentication manager with support for multiple authentication drivers, tenant isolation, and seamless tenant switching

v1.0.0(4mo ago)6254↓43.3%MITPHPPHP ^8.1|^8.2|^8.3CI passing

Since Jan 3Pushed 4mo agoCompare

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

READMEChangelogDependencies (13)Versions (2)Used By (0)

LaraTenAuth
===========

[](#laratenauth)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1f6e11dc4172f7531592549164905cdfc6f19cd4bbc444c218a56a429596eb84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365706568722d6d6f6873656e692f6c61726174656e617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sepehr-mohseni/laratenauth)[![Tests](https://camo.githubusercontent.com/f85c3a0dcc87a3d2cdd744653eda42b16406ea9b2f1f7718e61c5095f9dae1d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7365706568722d6d6f6873656e692f6c61726174656e617574682f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/sepehr-mohseni/laratenauth/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/18c03c6670b419c0f2dd62d09953bb4a9cf19c47e3fb526630d839edc50c9295/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365706568722d6d6f6873656e692f6c61726174656e617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sepehr-mohseni/laratenauth)[![License](https://camo.githubusercontent.com/88f0616b0d2e45aa62c1202796b46486987ebe18df8b4c048f8d89637f6f7628/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7365706568722d6d6f6873656e692f6c61726174656e617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sepehr-mohseni/laratenauth)

A comprehensive multi-tenant authentication package for Laravel applications. LaraTenAuth provides complete tenant isolation, multiple authentication drivers, role-based access control, and seamless tenant switching capabilities.

Features
--------

[](#features)

- 🏢 **Multiple Tenant Resolution Strategies** - Subdomain, domain, path, header, or custom strategies
- 🔐 **Tenant-Scoped Authentication** - Session and token-based guards with tenant isolation
- 👥 **Multi-Tenant User Support** - Users can belong to multiple tenants with different roles
- 🎭 **Role &amp; Permission Management** - Per-tenant roles and permissions for fine-grained access control
- 🔄 **Tenant Switching** - Switch between tenants while maintaining session state
- 🎫 **Tenant-Scoped API Tokens** - Create tokens scoped to specific tenants
- 🛡️ **Security Features** - Impersonation support, cross-tenant access control
- ⚡ **Performance Optimized** - Built-in caching for tenant resolution
- 🧪 **Fully Tested** - Comprehensive test suite with 90%+ coverage

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

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.x, 11.x, or 12.x

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

[](#installation)

You can install the package via composer:

```
composer require sepehr-mohseni/laratenauth
```

Publish the configuration file:

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

Publish the migrations:

```
php artisan vendor:publish --tag=laratenauth-migrations
```

Run the migrations:

```
php artisan migrate
```

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

[](#configuration)

The configuration file is located at `config/laratenauth.php`. Key configuration options:

```
return [
    // The tenant model class
    'tenant_model' => \Sepehr_Mohseni\LaraTenAuth\Models\Tenant::class,

    // The user model class
    'user_model' => \App\Models\User::class,

    // Tenant resolution strategies (order matters)
    'resolution' => [
        'strategies' => ['subdomain', 'domain', 'header'],
        'central_domains' => ['localhost', 'your-app.com'],
        'header_name' => 'X-Tenant-ID',
        'cache_enabled' => true,
        'cache_ttl' => 3600,
    ],

    // Security settings
    'security' => [
        'allow_impersonation' => false,
        'cross_tenant_auth' => false,
    ],
];
```

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

[](#quick-start)

### 1. Prepare Your User Model

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

Add the `HasTenants` and `HasTenantTokens` traits to your User model:

```
