-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathClientCommand.php
118 lines (97 loc) · 3.32 KB
/
ClientCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Sysvale\Mongodb\Console;
use Sysvale\Mongodb\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Console\ClientCommand as PassportClientCommand;
class ClientCommand extends PassportClientCommand
{
/**
* Create a new personal access client.
*
* @param \Laravel\Passport\ClientRepository $clients
* @return void
*/
protected function createPersonalClient(ClientRepository $clients)
{
$name = $this->option('name') ?: $this->ask(
'What should we name the personal access client?',
config('app.name').' Personal Access Client'
);
$client = $clients->createPersonalAccessClient(
null, $name, 'http://localhost'
);
$this->info('Personal access client created successfully.');
$this->patchedOutputClientDetails($client);
}
/**
* Create a new password grant client.
*
* @param \Laravel\Passport\ClientRepository $clients
* @return void
*/
protected function createPasswordClient(ClientRepository $clients)
{
$name = $this->option('name') ?: $this->ask(
'What should we name the password grant client?',
config('app.name').' Password Grant Client'
);
$client = $clients->createPasswordGrantClient(
null, $name, 'http://localhost'
);
$this->info('Password grant client created successfully.');
$this->patchedOutputClientDetails($client);
}
/**
* Create a client credentials grant client.
*
* @param \Laravel\Passport\ClientRepository $clients
* @return void
*/
protected function createClientCredentialsClient(ClientRepository $clients)
{
$name = $this->option('name') ?: $this->ask(
'What should we name the client?',
config('app.name').' ClientCredentials Grant Client'
);
$client = $clients->create(
null, $name, ''
);
$this->info('New client created successfully.');
$this->patchedOutputClientDetails($client);
}
/**
* Create a authorization code client.
*
* @param \Laravel\Passport\ClientRepository $clients
* @return void
*/
protected function createAuthCodeClient(ClientRepository $clients)
{
$userId = $this->option('user_id') ?: $this->ask(
'Which user ID should the client be assigned to?'
);
$name = $this->option('name') ?: $this->ask(
'What should we name the client?'
);
$redirect = $this->option('redirect_uri') ?: $this->ask(
'Where should we redirect the request after authorization?',
url('/auth/callback')
);
$client = $clients->create(
$userId, $name, $redirect, false, false, ! $this->option('public')
);
$this->info('New client created successfully.');
$this->patchedOutputClientDetails($client);
}
/**
* Output the client's ID and secret key.
*
* @param \Laravel\Passport\Client $client
* @return void
*/
protected function patchedOutputClientDetails(Client $client)
{
$this->line('<comment>Client ID:</comment> '.$client->id);
$this->line('<comment>Client secret:</comment> '.$client->secret);
}
}