33namespace Laravel \Passport \Console ;
44
55use Illuminate \Console \Command ;
6+ use Laravel \Passport \Passport ;
67
78class InstallCommand extends Command
89{
@@ -12,6 +13,7 @@ class InstallCommand extends Command
1213 * @var string
1314 */
1415 protected $ signature = 'passport:install
16+ {--uuids : Use UUIDs for all client IDs}
1517 {--force : Overwrite keys they already exist}
1618 {--length=4096 : The length of the private key} ' ;
1719
@@ -32,7 +34,54 @@ public function handle()
3234 $ provider = in_array ('users ' , array_keys (config ('auth.providers ' ))) ? 'users ' : null ;
3335
3436 $ this ->call ('passport:keys ' , ['--force ' => $ this ->option ('force ' ), '--length ' => $ this ->option ('length ' )]);
37+
38+ if ($ this ->option ('uuids ' )) {
39+ $ this ->configureUuids ();
40+ }
41+
3542 $ this ->call ('passport:client ' , ['--personal ' => true , '--name ' => config ('app.name ' ).' Personal Access Client ' ]);
3643 $ this ->call ('passport:client ' , ['--password ' => true , '--name ' => config ('app.name ' ).' Password Grant Client ' , '--provider ' => $ provider ]);
3744 }
45+
46+ /**
47+ * Configure Passport for client UUIDs.
48+ *
49+ * @return void
50+ */
51+ protected function configureUuids ()
52+ {
53+ $ this ->call ('vendor:publish ' , ['--tag ' => 'passport-config ' ]);
54+ $ this ->call ('vendor:publish ' , ['--tag ' => 'passport-migrations ' ]);
55+
56+ config (['passport.client_uuids ' => true ]);
57+ Passport::setClientUuids (true );
58+
59+ $ this ->replaceInFile (config_path ('passport.php ' ), 'false ' , 'true ' );
60+ $ this ->replaceInFile (database_path ('migrations/2016_06_01_000001_create_oauth_auth_codes_table.php ' ), '$table->unsignedBigInteger( \'client_id \'); ' , '$table->uuid( \'client_id \'); ' );
61+ $ this ->replaceInFile (database_path ('migrations/2016_06_01_000002_create_oauth_access_tokens_table.php ' ), '$table->unsignedBigInteger( \'client_id \'); ' , '$table->uuid( \'client_id \'); ' );
62+ $ this ->replaceInFile (database_path ('migrations/2016_06_01_000004_create_oauth_clients_table.php ' ), '$table->bigIncrements( \'id \'); ' , '$table->uuid( \'id \')->primary(); ' );
63+ $ this ->replaceInFile (database_path ('migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php ' ), '$table->unsignedBigInteger( \'client_id \'); ' , '$table->uuid( \'client_id \'); ' );
64+
65+ if ($ this ->confirm ('In order to finish configuring client UUIDs, we need to rebuild the Passport database tables. Would you like to rollback and re-run your last migration? ' )) {
66+ $ this ->call ('migrate:rollback ' );
67+ $ this ->call ('migrate ' );
68+ $ this ->line ('' );
69+ }
70+ }
71+
72+ /**
73+ * Replace a given string in a given file.
74+ *
75+ * @param string $path
76+ * @param string $search
77+ * @param string $replace
78+ * @return void
79+ */
80+ protected function replaceInFile ($ path , $ search , $ replace )
81+ {
82+ file_put_contents (
83+ $ path ,
84+ str_replace ($ search , $ replace , file_get_contents ($ path ))
85+ );
86+ }
3887}
0 commit comments