- Install passport
composer require laravel/passport
- Run migrations
php artisan migrate
- Run install passport
php artisan passport:install
- Add Trait HasApiTokens
On a User model add HasApiTokens trait
- Add Passport routes
// AuthServiceProvider.php
Passport::routes()
- config/auth.php configuration file change token to passport
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
- Publish the passport vue components
php artisan vendor:publish --tag=passport-components
- Register components
npm install
// add on resources/assets/js/app.js
Vue.component(
'passport-clients',
require('./components/passport/Clients.vue')
);
Vue.component(
'passport-authorized-clients',
require('./components/passport/AuthorizedClients.vue')
);
Vue.component(
'passport-personal-access-tokens',
require('./components/passport/PersonalAccessTokens.vue')
);
- Generate auth
php artisan make:auth
- Put the components in a view
<passport-clients></passport-clients>
<passport-authorized-clients></passport-authorized-clients>
<passport-personal-access-tokens></passport-personal-access-tokens>
npm run watch
- Use the authentication token
The client must make a token request to the oauth/token route by sending the following parameters
let data = {
client_id: 2,
client_secret: secret,
grant_type: 'password',
username: [email protected],
password: secreto
}
NOTE: Steps 7, 8 and 10 are not necessary.