2
'ttl' => null,
'refresh_ttl' => null,

I need the token does not expire.. It does not work, it always returns "error": "token expired"

4 Answers4

6

In the file vendor/tymon/jwt-auth/config/config.php change the line

'ttl' => env('JWT_TTL', 60),

by the

'ttl' => env('JWT_TTL', null),

Also remove exp in this line

 'required_claims' => [
        'iss',
        'iat',
        'exp',
        'nbf',
        'sub',
        'jti',
    ],

Works for my

1

Steps for not expiring login in JWTAuth:

  1. Open jwt.php in config folder (if it not available then publish the jwt.php file using this command in project==>

php artisan vendor:publish --provider="Tymon\JWTAuthProviders\JWTAuthServiceProvider" )

  1. Change

'ttl' => env('JWT_TTL', 60), to

'ttl' => env('JWT_TTL', null),

  1. remove exp in this line:-

'required_claims' => [ 'iss', 'iat', 'exp', 'nbf', 'sub', 'jti', ],

Ali
  • 202
  • 1
  • 10
0

This question is quite vague as we don't know which library/component is used to generate the Jot so we cannot know the way expiration claims are managed. In general, to get a Jot that does not expire, such claims (exp, ttl or refresh_ttl) should not be part of the payload.

The following token will expire in 3600 sec.

{
    'iss': 'my-service'
    'aud': 'your-service'
    'sub': 'my-client'
    'ttl': 3600
}

The following token should never expire.

{
    'iss': 'my-service'
    'aud': 'your-service'
    'sub': 'my-client'
}
Spomky-Labs
  • 15,473
  • 5
  • 40
  • 64
0

If you don't want to expire the token conditionally.

  1. Remove exp from required claims in config/jwt.php
  2. Add this code snippet to set TTL to null within the controller.
if ( // your condition ) {
    $this->guard()->setTTL(null);
}
Aqib
  • 304
  • 3
  • 5