Increase/Reset and manage jwt token expirattion time in wordpress using filter.

Use jwt_auth_token_before_sign filter for managing JWT token.

add_filter( 'jwt_auth_token_before_sign', 'increase_expiry_time_token', 10, 2 );

function increase_expiry_time_token( $token, $user)
{
  $issuedAt = time();
  $notBefore = apply_filters('jwt_auth_not_before', $issuedAt, $issuedAt);
  $expire = apply_filters('jwt_auth_expire', $issuedAt + (24*60*60*365*10), $issuedAt);
  $token = array(
    'iss' => get_bloginfo('url'),
    'iat' => $issuedAt,
    'nbf' => $notBefore,
    'exp' => $expire,
    'data' => array(
        'user' => array(
            'id' => $user->data->ID,
        )
    )
);

  return  $token;
}

0 Comments

Leave a Comment