HDTuto.com

Laravel - How to Set Lifetime Expiration Time of Passport Access Token?



Hello all! In this article, we will talk about laravel passport personal access token lifetime. i would like to show you passport expire time lifetime laravel. This post will give you simple example of laravel passport token expire time lifetime. This post will give you simple example of laravel passport token lifetime.

we can increase token expire time of access token using tokensExpireIn(). we can increase refresh token expire time of access token using refreshTokensExpireIn(). we can increase personal access token expire time of access token using personalAccessTokensExpireIn().

Let's see bellow example to set longer time of expire access token in laravel 5 application.

Example 1: app/Provides/AuthServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider

{

/**

* The policy mappings for the application.

*

* @var array

*/

protected $policies = [

];

/**

* Register any authentication / authorization services.

*

* @return void

*/

public function boot()

{

$this->registerPolicies();

Passport::routes();

Passport::tokensExpireIn(now()->addDays(30));

Passport::refreshTokensExpireIn(now()->addDays(30));

Passport::personalAccessTokensExpireIn(now()->addDays(30));

}

}

Example 2: app/Provides/AuthServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider

{

/**

* The policy mappings for the application.

*

* @var array

*/

protected $policies = [

];

/**

* Register any authentication / authorization services.

*

* @return void

*/

public function boot()

{

$this->registerPolicies();

Passport::routes();

Passport::tokensExpireIn(now()->addYears(5));

Passport::refreshTokensExpireIn(now()->addYears(5));

Passport::personalAccessTokensExpireIn(now()->addYears(5));

}

}

I hope it can help you...




May 2, 2020 | Category : Laravel



Blog Search