mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-13 18:54:04 +00:00
darkons' rewrite
This commit is contained in:
parent
985df20327
commit
9435577f5e
1 changed files with 48 additions and 42 deletions
|
|
@ -8,7 +8,6 @@ section: content
|
||||||
|
|
||||||
> **Tip:** If you only want to write a SPA application but don't need an API for some other use (for example, a mobile application), you can avoid much of the complexity by using [Inertia.js](https://inertiajs.com/).
|
> **Tip:** If you only want to write a SPA application but don't need an API for some other use (for example, a mobile application), you can avoid much of the complexity by using [Inertia.js](https://inertiajs.com/).
|
||||||
|
|
||||||
**Very important:** Don't use the command `passport:install` to avoid issues.
|
|
||||||
|
|
||||||
## Passport use cases
|
## Passport use cases
|
||||||
|
|
||||||
|
|
@ -23,17 +22,34 @@ section: content
|
||||||
|
|
||||||
### **Using Passport only in central application** {#using-passport-only-in-central-application}
|
### **Using Passport only in central application** {#using-passport-only-in-central-application}
|
||||||
You don't have to do anything special in this use case, just install **Laravel Passport** as its official documentation explains:
|
You don't have to do anything special in this use case, just install **Laravel Passport** as its official documentation explains:
|
||||||
|
|
||||||
[Laravel Passport official documentation](https://laravel.com/docs/9.x/passport)
|
[Laravel Passport official documentation](https://laravel.com/docs/9.x/passport)
|
||||||
|
|
||||||
### **Using Passport only in tenant application** {#using-passport-only-in-tenant-application}
|
### **Using Passport only in tenant application** {#using-passport-only-in-tenant-application}
|
||||||
To use **Laravel Passport** inside the tenant application, you must follow the following steps:
|
To use **Laravel Passport** inside the tenant application, you must follow the following steps:
|
||||||
|
|
||||||
1. Add this code to the `register` method in your `AppServiceProvider` to prevent Passport migrations from running in the central application:
|
1. Don't use `passport:install` command. Instead of that, publish `migrations` and `config` manually:
|
||||||
|
- Run `php artisan vendor:publish --tag=passport-migrations` command and **MOVE** (not copy) all of them to `database/migrations/tenant/` directory.
|
||||||
|
|
||||||
|
- Run `php artisan vendor:publish --tag=passport-config` command. After that, open `config/passport.php` file and set storage database connection to `null`. This will make Passport use the default connection:
|
||||||
|
```php
|
||||||
|
return [
|
||||||
|
'storage' => [
|
||||||
|
'database' => [
|
||||||
|
'connection' => null,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Add this code to the `register` method in your `AppServiceProvider` to prevent Passport migrations from running in the central application:
|
||||||
```php
|
```php
|
||||||
Passport::ignoreMigrations();
|
Passport::ignoreMigrations();
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Register Passport routes adding this code to the `boot` method in your `AuthServiceProvider`:
|
3. Apply Passport migrations running `php artisan migrate` command.
|
||||||
|
|
||||||
|
4. Register Passport routes adding this code to the `boot` method in your `AuthServiceProvider`:
|
||||||
```php
|
```php
|
||||||
Passport::routes(null, ['middleware' => [
|
Passport::routes(null, ['middleware' => [
|
||||||
InitializeTenancyByDomain::class, // Or whatever tenant identification middlewares you're going to use
|
InitializeTenancyByDomain::class, // Or whatever tenant identification middlewares you're going to use
|
||||||
|
|
@ -41,20 +57,7 @@ To use **Laravel Passport** inside the tenant application, you must follow the f
|
||||||
]]);
|
]]);
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Publish Passport migrations running `php artisan vendor:publish --tag=passport-migrations` command and **move** (not copy) all of them to `database/migrations/tenant/` directory.
|
5. To automatically create Passport Clients in your tenant databases, add the following code to your tenant seeder class:
|
||||||
|
|
||||||
4. Publish Passport config file running `php artisan vendor:publish --tag=passport-config` command. After that, open `config/passport.php` file and set storage database connection to `null`. This will make Passport use the default connection:
|
|
||||||
```php
|
|
||||||
return [
|
|
||||||
'storage' => [
|
|
||||||
'database' => [
|
|
||||||
'connection' => null,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
```
|
|
||||||
|
|
||||||
5. Create Passport Clients in your tenant database seeder like this:
|
|
||||||
```php
|
```php
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +67,7 @@ To use **Laravel Passport** inside the tenant application, you must follow the f
|
||||||
$client->createPersonalAccessClient(null, 'Default personal access client', 'http://your.redirect.path');
|
$client->createPersonalAccessClient(null, 'Default personal access client', 'http://your.redirect.path');
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
*You can set your tenants database seeder class in `config/tenancy.php` file at `seeder_parameters` key.*
|
*You can set your tenant database seeder class in `config/tenancy.php` file at `seeder_parameters` key.*
|
||||||
|
|
||||||
6. Create Passport keys following [Manage Passport keys](#manage-passport-keys) section.
|
6. Create Passport keys following [Manage Passport keys](#manage-passport-keys) section.
|
||||||
|
|
||||||
|
|
@ -72,19 +75,10 @@ To use **Laravel Passport** inside the tenant application, you must follow the f
|
||||||
### **Using Passport in both the central and tenant application** {#using-passport-in-both-the-central-and-tenant-application}
|
### **Using Passport in both the central and tenant application** {#using-passport-in-both-the-central-and-tenant-application}
|
||||||
To use **Laravel Passport** on central and tenant application, you must follow the following steps:
|
To use **Laravel Passport** on central and tenant application, you must follow the following steps:
|
||||||
|
|
||||||
1. Enable [Universal Routes]({{ $page->link('universal-routes') }}) feature.
|
1. Don't use `passport:install` command. Instead of that, publish `migrations` and `config` manually:
|
||||||
|
- Run `php artisan vendor:publish --tag=passport-migrations` command and **COPY** all of them to `database/migrations/tenant/` directory.
|
||||||
|
|
||||||
2. Register Passport routes adding this code to the `boot` method in your `AuthServiceProvider`:
|
- Run `php artisan vendor:publish --tag=passport-config` command. After that, open `config/passport.php` file and set storage database connection to `null`. This will make Passport use the default connection:
|
||||||
```php
|
|
||||||
Passport::routes(null, ['middleware' => [
|
|
||||||
'universal',
|
|
||||||
PreventAccessFromCentralDomains::class,
|
|
||||||
]]);
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Publish Passport migrations running `php artisan vendor:publish --tag=passport-migrations` command and make a **copy** of all of them to `database/migrations/tenant/` directory.
|
|
||||||
|
|
||||||
4. Publish Passport config file running `php artisan vendor:publish --tag=passport-config` command. After that, open `config/passport.php` file and set storage database connection to `null`. This will make Passport use the default connection:
|
|
||||||
```php
|
```php
|
||||||
return [
|
return [
|
||||||
'storage' => [
|
'storage' => [
|
||||||
|
|
@ -95,7 +89,19 @@ To use **Laravel Passport** on central and tenant application, you must follow t
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Create Passport Clients in your central and tenant database seeders like this:
|
2. Apply Passport migrations running `php artisan migrate` command.
|
||||||
|
|
||||||
|
3. Enable [Universal Routes]({{ $page->link('universal-routes') }}) feature to allow Passport routes being accessible in both apps.
|
||||||
|
|
||||||
|
4. Register Passport routes adding this code to the `boot` method in your `AuthServiceProvider`:
|
||||||
|
```php
|
||||||
|
Passport::routes(null, ['middleware' => [
|
||||||
|
'universal',
|
||||||
|
InitializeTenancyByDomain::class, // Or whatever tenant identification middlewares you're going to use
|
||||||
|
]]);
|
||||||
|
```
|
||||||
|
|
||||||
|
5. To create Passport Clients in your central app, just use `php artisan passport:client` commands. To automatically create Passport Clients in your tenant databases, add the following code to your tenant seeder class:
|
||||||
```php
|
```php
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +111,7 @@ To use **Laravel Passport** on central and tenant application, you must follow t
|
||||||
$client->createPersonalAccessClient(null, 'Default personal access client', 'http://your.redirect.path');
|
$client->createPersonalAccessClient(null, 'Default personal access client', 'http://your.redirect.path');
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
*You can set your tenants database seeder class in `config/tenancy.php` file at `seeder_parameters` key.*
|
*You can set your tenant database seeder class in `config/tenancy.php` file at `seeder_parameters` key.*
|
||||||
|
|
||||||
6. Create Passport keys following [Manage Passport keys](#manage-passport-keys) section.
|
6. Create Passport keys following [Manage Passport keys](#manage-passport-keys) section.
|
||||||
|
|
||||||
|
|
@ -124,5 +130,5 @@ Once the [Tenant Config]({{ $page->link('features/tenant-config') }}) feature is
|
||||||
\Stancl\Tenancy\Features\TenantConfig::$storageToConfigMap = [
|
\Stancl\Tenancy\Features\TenantConfig::$storageToConfigMap = [
|
||||||
'passport_public_key' => 'passport.public_key',
|
'passport_public_key' => 'passport.public_key',
|
||||||
'passport_private_key' => 'passport.private_key',
|
'passport_private_key' => 'passport.private_key',
|
||||||
],
|
];
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue