Feat: Configure Laravel Passport for API authentication
- Added `PassportServiceProvider` to configure token expiration intervals. - Updated `User` model with `HasApiTokens` trait and `OAuthenticatable` interface for Passport support. - Registered `PassportServiceProvider` in `bootstrap/providers.php`.
This commit is contained in:
parent
e791c08ce1
commit
fb7b1e3721
@ -18,6 +18,8 @@
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Laravel\Passport\Contracts\OAuthenticatable;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
@ -26,10 +28,10 @@
|
||||
*/
|
||||
#[Fillable(['name', 'email', 'password', 'immutable_id'])]
|
||||
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
||||
final class User extends Authenticatable implements OidcUserInterface
|
||||
final class User extends Authenticatable implements OAuthenticatable, OidcUserInterface
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, HasOidcClaims, SoftDeletes;
|
||||
use HasApiTokens, HasFactory, HasOidcClaims, SoftDeletes;
|
||||
|
||||
use HasRoles;
|
||||
use Notifiable;
|
||||
|
||||
21
app/Providers/PassportServiceProvider.php
Normal file
21
app/Providers/PassportServiceProvider.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Carbon\CarbonInterval;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
class PassportServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void {}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Passport::tokensExpireIn(CarbonInterval::minute(30));
|
||||
Passport::refreshTokensExpireIn(CarbonInterval::days(15));
|
||||
Passport::personalAccessTokensExpireIn(CarbonInterval::months(6));
|
||||
}
|
||||
}
|
||||
@ -6,4 +6,5 @@
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\FortifyServiceProvider::class,
|
||||
App\Providers\DirectiveServiceProvider::class,
|
||||
App\Providers\PassportServiceProvider::class,
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user