Laravel Passport Access Token Expire Lifetime
In this post we will give you information about Laravel Passport Access Token Expire Lifetime. Hear we will give you detail about Laravel Passport Access Token Expire LifetimeAnd how to use it also give you demo for it if it is necessary.
In this post, we will learn how to set lifetime expiration time of passport access token in laravel. we can set personal access token expiry time longer and also event shorter using tokensExpireIn, refreshTokensExpireIn, and personalAccessTokensExpireIn methods.
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 AppProviders;
use IlluminateSupportFacadesGate;
use IlluminateFoundationSupportProvidersAuthServiceProvider 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 AppProviders;
use IlluminateSupportFacadesGate;
use IlluminateFoundationSupportProvidersAuthServiceProvider 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…
Hope this code and post will helped you for implement Laravel Passport Access Token Expire Lifetime. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs