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