Laravel Passport Multi auth API

CMD

1. composer require laravel/passport

if any error then goto php.ini and enable sodium extension

2. php artisan passport:install OR ( if showing error )
2. php artisan passport:install --force
config/auth

'guards' => [

  'web' => [
    'driver' => 'session',
    'provider' => 'users',
   ],

  'api' => [
    'driver' => 'passport',
    'provider' => 'users'
   ],

  'customers' => [
    'driver' => 'session',
    'provider' => 'customer'
  ],

  'api-customers' => [
    'driver' => 'passport',
    'provider' => 'customer'
  ],

  'merchant' => [
    'driver' => 'session',
    'provider' => 'merchant'
  ],

  'api-merchant' => [
    'driver' => 'passport',
    'provider' => 'merchant'
  ],

],
config/auth

'providers' => [
   'users' => [
     'driver' => 'eloquent',
     'model' => App\Models\User::class,
   ],

   'merchant' => [
     'driver' => 'eloquent',
     'model' => App\Models\Merchant::class,
   ],

   'customer' => [
     'driver' => 'eloquent',
     'model' => App\Models\Customer::class,
   ],

],
Create two migrations:

1. php artisan make:migration Oauth_personal_access_clients

public function up(): void
{ 
Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
$table->id();
$table->string('client_id')->nullable();
$table->timestamps();
});
}


2. php artisan make:migration Oauth_clients

public function up(): void
{

  Schema::create('oauth_clients', function (Blueprint $table) {
  $table->id();
  $table->string('user_id');
  $table->string('name');
  $table->text('secret');
  $table->string('provider');
  $table->string('redirect');
  $table->string('personal_access_client');
  $table->string('password_client');
  $table->string('revoked');
  $table->timestamps();

});

}

public function down(): void
{
  Schema::dropIfExists('oauth_clients');
}

 

 

Leave a Reply