Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

php - Laravel: After upgrade JWT then session expire become too often

so, i upgrade my jwt package on my Laravel v5.8, I need to upgrade because of security issue. However, upgrading jwt is not easy, too many trial & error. Finally, i found a solution from it's github repository here then jwt upgrade is finish.

==========

The summary of solution by adding:

(1) Upgrade jwt by composer require tymon/jwt-auth:1.0.* --prefer-source

(2) Change below line in config/app.php, before:

'providers' => [
...
'TymonJWTAuthProvidersJWTAuthServiceProvider' ,
...
]

into

'providers' => [
...
'TymonJWTAuthProvidersLaravelServiceProvider' ,
...
]

(3) Add implements JWTSubject into User Model Class

(4) Add below line into User Model Class:

public function getJWTIdentifier()
{
   return $this->getKey();
}

public function getJWTCustomClaims()
{
   return [];
}

(5) run php artisan vendor:publish --provider="TymonJWTAuthProvidersLaravelServiceProvider"

==========

However, it has side effect.

Now, every login sessions do not last long.

Before this fix, it sometimes need a month for a login session to expire, but now it just need a couple of hour. Moreover, no other logic/coding added except above.

Any Idea/Solution?

Thank You in Advance...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Time to live is defined in the config/jwt.php.

See the line that says 'ttl' => env('JWT_TTL', 60) which means by default the token will be valid for 1 hour.

If you don't already have that, be sure to run the following command to publish the package config file:

php artisan vendor:publish --provider="TymonJWTAuthProvidersLaravelServiceProvider"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...