How to uninstall Laravel Passport

放肆的年华 提交于 2020-06-10 08:13:36

问题


I've decided to use JWT and completely remove Laravel Passport from the project.

I was trying to start with composer remove laravel/passport. However, it does no good:

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'Laravel\Passport\Passport' not found


Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

Removal failed, reverting ./composer.json to its original content.

What could be the right and safe removing procedure?


回答1:


You can remove passport by manually deleting this line "laravel/passport": "^4.0" in your composer.json file then run composer update.

If you're running Laravel 5.4 or below, make sure to remove this line in your app.config file Laravel\Passport\PassportServiceProvider::class

And all classes that relies on passport must be edited as well. The most common classes are:

  1. User model, remove the HasApiToken trait.
  2. AuthServiceProvider, remove Passport::routes(); in your boot method.
  3. Your config/auth.php, change your driver option for api authentication



回答2:


After following Paul's steps. Remove the Passport Migrations in database migrations table and run command artisan migrate:refresh.




回答3:


With Laravel 7, I did it this way:

Step 1. In app/Providers/AuthServiceProvider.php file remove these two lines:

use Laravel\Passport\Passport;
Passport::routes();

Step 2.

$ composer remove laravel/passport
$ rm -r ./resources/js/components/passport # if any
$ rm -r ./resources/views/vendor/passport # if any

Step 3. In the file resources/js/app.js, remove passport components registration. You may also find and remove these registered components if you used it somewhere:

$ grep -rn 'passport-authorized-clients'     resources/js/*
$ grep -rn 'passport-personal-access-tokens' resources/js/*
$ grep -rn 'passport-clients'                resources/js/*

Step 4. Find and remove HasApiTokens from your models:

$ grep -rn HasApiTokens * 

Remove also the import line going with it:

use Laravel\Passport\HasApiTokens;

Step 5. Remove oauth keys

$ rm storage/oauth-*.key

Step 6. In the file config/auth, revert the api driver in guards from passport to token.

Step 7. Drop Passport tables and clean migration table

$ php artisan tinker
>>> Schema::drop('oauth_access_tokens');
>>> Schema::drop('oauth_auth_codes');
>>> Schema::drop('oauth_clients');
>>> Schema::drop('oauth_personal_access_clients');
>>> Schema::drop('oauth_refresh_tokens');
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_access_tokens_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_auth_codes_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_clients_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_personal_access_clients_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_refresh_tokens_table')->delete();
>>> exit

Step 8. And finally, refresh your installation:

$ composer dump-autoload
$ php artisan optimize:clear
$ npm run dev


来源:https://stackoverflow.com/questions/47567249/how-to-uninstall-laravel-passport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!