Skip to content

Commit a75f0a9

Browse files
[11.x] Add Provider Guard to ClientRepository for Personal Access Clients (#1655)
* Added provider guard to Password Grant Client. * Add argument provider in `InstallCommand` * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent bf5e6f4 commit a75f0a9

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/ClientRepository.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ public function create($userId, $name, $redirect, $provider = null, $personalAcc
161161
* @param int|null $userId
162162
* @param string $name
163163
* @param string $redirect
164+
* @param string|null $provider
164165
* @return \Laravel\Passport\Client
165166
*/
166-
public function createPersonalAccessClient($userId, $name, $redirect)
167+
public function createPersonalAccessClient($userId, $name, $redirect, $provider = null)
167168
{
168-
return tap($this->create($userId, $name, $redirect, null, true), function ($client) {
169+
return tap($this->create($userId, $name, $redirect, $provider, true), function ($client) {
169170
$accessClient = Passport::personalAccessClient();
170171
$accessClient->client_id = $client->getKey();
171172
$accessClient->save();

src/Console/ClientCommand.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ protected function createPersonalClient(ClientRepository $clients)
6363
config('app.name').' Personal Access Client'
6464
);
6565

66+
$provider = $this->promptForProvider();
67+
6668
$client = $clients->createPersonalAccessClient(
67-
null, $name, 'http://localhost'
69+
null, $name, 'http://localhost', $provider
6870
);
6971

7072
$this->info('Personal access client created successfully.');
@@ -85,13 +87,7 @@ protected function createPasswordClient(ClientRepository $clients)
8587
config('app.name').' Password Grant Client'
8688
);
8789

88-
$providers = array_keys(config('auth.providers'));
89-
90-
$provider = $this->option('provider') ?: $this->choice(
91-
'Which user provider should this client use to retrieve users?',
92-
$providers,
93-
in_array('users', $providers) ? 'users' : null
94-
);
90+
$provider = $this->promptForProvider();
9591

9692
$client = $clients->createPasswordGrantClient(
9793
null, $name, 'http://localhost', $provider
@@ -154,6 +150,22 @@ protected function createAuthCodeClient(ClientRepository $clients)
154150
$this->outputClientDetails($client);
155151
}
156152

153+
/**
154+
* Ask the user what user provider should be used.
155+
*
156+
* @return string
157+
*/
158+
protected function promptForProvider()
159+
{
160+
$providers = array_keys(config('auth.providers'));
161+
162+
return $this->option('provider') ?: $this->choice(
163+
'Which user provider should this client use to retrieve users?',
164+
$providers,
165+
in_array('users', $providers) ? 'users' : null
166+
);
167+
}
168+
157169
/**
158170
* Output the client's ID and secret key.
159171
*

src/Console/InstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handle()
3939
$this->configureUuids();
4040
}
4141

42-
$this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client']);
42+
$this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client', '--provider' => $provider]);
4343
$this->call('passport:client', ['--password' => true, '--name' => config('app.name').' Password Grant Client', '--provider' => $provider]);
4444
}
4545

0 commit comments

Comments
 (0)