Skip to content

Instantly share code, notes, and snippets.

@JuanVqz
Created May 5, 2018 04:18
Show Gist options
  • Save JuanVqz/5a4db395fb1292d73bab70f4585bb46d to your computer and use it in GitHub Desktop.
Save JuanVqz/5a4db395fb1292d73bab70f4585bb46d to your computer and use it in GitHub Desktop.
Passport configuration

Install passport step by step

  1. Install passport
composer require laravel/passport
  1. Run migrations
php artisan migrate
  1. Run install passport
php artisan passport:install
  1. Add Trait HasApiTokens

On a User model add HasApiTokens trait

  1. Add Passport routes
// AuthServiceProvider.php

Passport::routes()
  1. config/auth.php configuration file change token to passport
'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],
  1. Publish the passport vue components
php artisan vendor:publish --tag=passport-components
  1. 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')
);
  1. Generate auth
php artisan make:auth
  1. 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
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment