1

The documentation Here suggests php artisan passport:client --client for creating a client, but I want to do it using a controller, or ideally, using the native JSON apis provided by passport. Is that possible at all or will I have to override the methods in Passport::client ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Riju Pramanik
  • 23
  • 1
  • 9

2 Answers2

2

Old question, but here's a 2021 answer for people finding this on Google.

I find calling Artisan commands from code unsavory, especially as @kishore-kadiyala mentioned because you get back printed output, rather than code.

Instead, you can use the Laravel\Passport\ClientRepository class to create a client directly:

use Laravel\Passport\ClientRepository;

// ... snip ...

$clients = App::make(ClientRepository::class);

// 1st param is the user_id - none for client credentials
// 2nd param is the client name
// 3rd param is the redirect URI - none for client credentials
$client = $clients->create(null, 'My Client Name', '');

Here, $client is a Laravel\Passport\Client instance directly. This is exactly how the Artisan command creates the clients anyway.

garrettmills
  • 660
  • 6
  • 13
0

You can do

Artisan::call('passport:client --client');

Look at Artisan