/laravel-passport-api

Ionic Framework + Laravel API with Passport Oauth2 Server implementation

Primary LanguagePHP

Laravel API with Passport Oauth2 Server

Implementation using Laravel Framework v5.6 and Laravel Passport's Oauth2 Server and examples provided on how to consume the API from multiple front end frameworks and other apps.

Requirements

  • Node.js
  • Laravel 5.6+

Steps

Install Laravel

$ composer install

Setup Laravel Auth

$ php artisan make:auth

Add Passport

$ composer require laravel/passport

Install Passport

$ php artisan passport:install

Run migrations

$ php artisan migrate

Add Passport Routes

In AuthServiceProvider.php

namespace App\Providers;

use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->registerPolicies();

        Passport::routes();
    }
}

Set Passport as Auth's API driver

In config/auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

Install Laravel Cors

$ composer require barryvdh/laravel-cors

Examples

Ionic Framework

Ionic 2 + Laravel Passport Login

React

(soon)

Inferno JS

(soon)

Marko JS

(soon)

Contributing

If you have any suggestions or improvements open an issue.

License

Software licensed under the MIT license.