https://github.com/romanturas/passport-laravel
How to install Laravel 8 passport for using from Vue Js
https://github.com/romanturas/passport-laravel
Last synced: 5 months ago
JSON representation
How to install Laravel 8 passport for using from Vue Js
- Host: GitHub
- URL: https://github.com/romanturas/passport-laravel
- Owner: RomanTuras
- Created: 2021-07-20T06:13:05.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-20T14:40:55.000Z (almost 5 years ago)
- Last Synced: 2025-04-08T11:26:17.247Z (about 1 year ago)
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How to install and setup passport in Laravel 8 for using from Vue Js
### To install Laravel Passport, run:
```
composer require laravel/passport
```
### Add the following provider in the config/app.php file:
```php
Laravel\Passport\PassportServiceProvider::class,
```
### Migrate Laravel Passport tables:
```
php artisan migrate
```
### And then install:
```
php artisan passport:install
```
### And now open `AuthServiceProvider.php` file. Add the following routes and expire time for token:
```php
public function boot()
{
$this->registerPolicies();
Passport::routes();
Passport::tokensExpireIn(Carbon::now()->addDays(15));
Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
}
```
### And uncomment in the `AuthServiceProvider.php` file:
```php
protected $policies = [
'App\Models\Model' => 'App\Policies\ModelPolicy',
];
```
### Now open `config/auth.php` file and set passport as your API driver.
```php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
```
### Add provider in the `config/app.php`
```php
'providers' => [
...
\Laravel\Passport\PassportServiceProvider::class,
]
```
### Update the Users Model:
```php
use HasFactory, Notifiable, HasApiTokens;
```
### Add `$middlewareGroups` into `app/Http/Kernel.php`:
```php
'web' => [
...
CreateFreshApiToken::class,
],
'api' => [
...
CreateFreshApiToken::class,
],
```
### Edit `app/Http\Middleware\VerifyCsrfToken`:
```php
protected $except = [
"api/*"
];
```
### If adding your routes inside the `web middleware` doesn't work for any reason, then try adding this to `$middleware` into `app/Http/Kernel.php`:
```php
protected $middleware = [
...
StartSession::class,
ShareErrorsFromSession::class,
];
```
### Try to use middleware in `route/api.php`, for example:
```php
Route::middleware('auth:api')->group(function () {
...
});
```
### Now `X-XSRF-TOKEN` will be added in the header automatically from your Vue Js code
---
### Don't forget about key's (deploy them to prod):
```
storage/oauth-private.key
storage/oauth-public.key
```
### And create all `oauth` tables in the remote DB