I don\'t get what I\'m doing wrong. I can\'t set token expiration time.
Yes, I just wasted one day to find this problem in VERSION = '5.8'.
For now, maybe we need modify your-project/vendor/laravel/passport/src/Passport.php.
D---> means Day Y---> means year M---> means Month
three types of token in passport
1.tokensExpireIn in 303 line.
personalAccessTokensExpireIn in 341 line .
refreshTokensExpireIn in 322 line.
you can do this:
$tokenResult = $user->createToken('Personal Access Token');
$token = $tokenResult->token;
$token->expires_at =
Carbon::now()->addDays(env('PERSONAL_ACCESS_TOKEN_EXPIRY__DAYS'));
$token->save();
File: AuthServiceProvider.php
Add these lines
use Laravel\Passport\Bridge\PersonalAccessGrant;
use League\OAuth2\Server\AuthorizationServer;
Add the following code in boot function
public function boot() {
Passport::routes();
$lifetime = new \DateInterval('PT24H'); // For 24hours
$this->app->get(AuthorizationServer::class)->enableGrantType(new PersonalAccessGrant(), $lifetime);
}
Here are the methods used to update expiration time for all the grant types :
Personal access token:
public function boot(){
$this->registerPolicies();
Passport::routes();
Passport::personalAccessTokensExpireIn(Carbon::now()->addHours(24));
Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
}
Rest all
public function boot(){
$this->registerPolicies();
Passport::routes();
Passport::tokensExpireIn(Carbon::now()->addHours(24));
Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
}
Just update the above code in the boot method of AuthServiceProvider.