- Install Jetstream with livewire:
composer require laravel/jetstream
php artisan jetstream:install livewire
See Docs for more info.
- Install this package:
composer require headerx/laravel-jetstream-passport
php artisan migrate
php artisan jetstream-passport:install
- in your user model replace the
Laravel\Sanctum\HasApiTokens
trait withLaravel\Passport\HasApiTokens
:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
- use Laravel\Sanctum\HasApiTokens;
+ use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
...
}
- in config/auth.php set the
api.driver
topassport
:
...
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
],
...
- replace the contents of resources/views/vendor/passport/authorize.blade.php with the following:
@include('jetstream-passport::authorize')
- replace the contents of resources/views/api/index.blade.php with the following:
@include('jetstream-passport::index')
You can publish the views with:
php artisan vendor:publish --provider="HeaderX\JetstreamPassport\JetstreamPassportServiceProvider" --tag="jetstream-passport-views"
- finally, in one of you application's service providers, add passport routes and define scopes for your passport tokens, and set up jetstream to use them, example:
<?php
// app/Providers/AuthServiceProvider.php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Jetstream\Jetstream;
use Laravel\Passport\Passport;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
// add passport routes
Passport::routes();
// define scopes for passport tokens
Passport::tokensCan([
'create' => 'Create resources',
'read' => 'Read Resources',
'update' => 'Update Resources',
'delete' => 'Delete Resources',
]);
// default scope for passport tokens
Passport::setDefaultScope([
// 'create',
'read',
// 'update',
// 'delete',
]);
// same as passport default above
Jetstream::defaultApiTokenPermissions(['read']);
// use passport scopes for jetstream token permissions
Jetstream::permissions(Passport::scopeIds());
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.