PHPackages                             cidekar/laravel-tenantmagic - 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. cidekar/laravel-tenantmagic

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

cidekar/laravel-tenantmagic
===========================

A multitenancy package for Laravel Passport.

v1.0.1(3y ago)03331MITPHPPHP ^7.4|^8.0

Since Oct 9Pushed 3y agoCompare

[ Source](https://github.com/Cidekar/laravel-tenantmagic)[ Packagist](https://packagist.org/packages/cidekar/laravel-tenantmagic)[ RSS](/packages/cidekar-laravel-tenantmagic/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

[![](https://user-images.githubusercontent.com/4164072/93266709-776d2800-f778-11ea-91a3-a48651b89882.png)](https://user-images.githubusercontent.com/4164072/93266709-776d2800-f778-11ea-91a3-a48651b89882.png)

Introduction
============

[](#introduction)

Laravel Passport makes password grant client authentication dead-simple for your API. Laravel Multitenancy makes a Laravel application tenant aware in minutes - feels like cheating. Tenantmagic, provides one approach to a making your Passport password grant client tenant aware. Before going through the rest of this documentation, take time to read [Laravel Multitenancy](https://spatie.be/docs/laravel-multitenancy/v1/installation/using-multiple-databases) and [Laravel Passport](https://laravel.com/docs/7.x/passport), if your unfamiliar. Tenantmagic is built on top of Laravel Passport and Laravel Multitenancy.

Motivation
----------

[](#motivation)

Multitenancy typically requires a user provide their authentication credentials and subdomain to get a token. Tenantmagic removes the need for a subdomain when logging into your multi-tenant application; provide a user name and password and the package will do the rest!

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

[](#installation)

This package can be installed with Composer:

`$ composer require "cidekar/tenantmagic:^1.0"`

Publish the configuration:

`php artisan vendor:publish --provider="Cidekar\Tenantmagic\TenantmagicServiceProvider" --tag="config"`

The configuration will be published to config/tenantmagic.php

The User model must use `UsesPassportModelMagic`:

```
    use Cidekar\Tenantmagic\Models\Concerns\UsesPassportModelMagic;

    class User extends Authenticatable
    {
        use UsesPassportModelMagic;
        ...
```

Please keep in mind this package assumes the grant client is stored in the landlord database. Users are stored in the tenant database.

Add the TenantmagicDomainTenantFinder to the multitenancy config:

```
    return [
        /*
        * This class is responsible for determining which tenant should be current
        * for the given request.
        *
        * This class should extend `Spatie\Multitenancy\TenantFinder\TenantFinder`
        *
        */
        'tenant_finder' => TenantmagicDomainTenantFinder::class,

        ...
```

Add the `TenantmagicPassportTask` to the `switch_tenant_tasks` array:

```
    return [
        /*
        * These tasks will be performed when switching tenants.
        *
        * A valid task is any class that implements Spatie\Multitenancy\Tasks\SwitchTenantTask
        */
        'switch_tenant_tasks' => [
            SwitchTenantDatabaseTask::class,
            TenantmagicPassportTask::class
        ],

        ...
```

Configure your tenant and landlord database connections:

```
    return [
        /*
        * The connection name to reach the tenant database.
        *
        * Set to `null` to use the default connection.
        */
        'tenant_database_connection_name' => 'tenant',

        /*
        * The connection name to reach the landlord database
        */
        'landlord_database_connection_name' => 'landlord',

        ...
```

X-Magictenant Header
--------------------

[](#x-magictenant-header)

Out of the box, Tenantmagic will return the `x-magictenant` header when responding to a successful authorization request. To reveal the domain and tenant name, the x-magictenant header value (i.e., non-extended notation, using "quoted-string") needs to be decoded:

```
    $response = $this->post($route);

    json_decode($response->headers->get('x-magictenant'));

    array:2 [
    0 => {
        "domain": "foo.com"
        "name": "Foo Dot Com"
    }
    1 => {
        "domain": "bar.net"
        "name": "Bar Dot Net"
    }];
```

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

[](#requirements)

- Your application is configured for [multitenancy](https://spatie.be/docs/laravel-multitenancy/v1/installation/using-multiple-databases) using a separate database for each tenant
- Passport is [installed and configured](https://laravel.com/docs/7.x/passport#installation)

Testing
-------

[](#testing)

To get started, create the following MySql databases:

- `laravel_tenantmagic_landlord`
- `laravel_tenantmagic_tenant_1`
- `laravel_tenantmagic_tenant_2`

Now, you may run the package's tests:

```
   $ composer test

    # Runtime:       PHP 7.4.0
    # Configuration: /var/www/packages/cidekar/laravel-tenantmagic/phpunit.xml
    # Warning:       Your XML configuration validates against a deprecated schema.
    # Suggestion:    Migrate your XML configuration using "--migrate-configuration"!
    # ...
```

Security
--------

[](#security)

Please do not publicly disclose security-related issues, email . Security vulnerabilities will be promptly addressed.

License
-------

[](#license)

Copyright 2020 Cidekar, LLC. All rights reserved.

[Apache License 2.0](./license.md)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 95.1% 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 ~20 days

Total

2

Last Release

1447d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b7adbb13a86882c38365348d6dca3f7ef8a43d789d80803fa843e2a0c314a9a?d=identicon)[packagist@cidekar.com](/maintainers/packagist@cidekar.com)

---

Top Contributors

[![harrisonde](https://avatars.githubusercontent.com/u/4164072?v=4)](https://github.com/harrisonde "harrisonde (39 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (2 commits)")

### Embed Badge

![Health badge](/badges/cidekar-laravel-tenantmagic/health.svg)

```
[![Health](https://phpackages.com/badges/cidekar-laravel-tenantmagic/health.svg)](https://phpackages.com/packages/cidekar-laravel-tenantmagic)
```

###  Alternatives

[dusterio/lumen-passport

Making Laravel Passport work with Lumen

6511.3M9](/packages/dusterio-lumen-passport)[corbosman/laravel-passport-claims

Add claims to Laravel Passport JWT Tokens

88655.9k](/packages/corbosman-laravel-passport-claims)[smartins/passport-multiauth

Add support to multi-auth on Laravel Passport

285324.2k1](/packages/smartins-passport-multiauth)[coderello/laravel-passport-social-grant

Social Grant for Laravel Passport

179607.4k3](/packages/coderello-laravel-passport-social-grant)[jeremy379/laravel-openid-connect

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

55342.3k2](/packages/jeremy379-laravel-openid-connect)[adaojunior/passport-social-grant

Social grant for Laravel Passport

116279.2k1](/packages/adaojunior-passport-social-grant)

PHPackages © 2026

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