Support » Plugin: JWT Auth - WordPress JSON Web Token Authentication » Expiration date for token

  • Resolved paxton111

    (@paxton111)


    Hi guys,

    Can you tell how to set expiration of the token and is this already set with the plugin?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Bagus

    (@contactjavas)

    Hi @paxton111 ,

    You can use jwt_auth_expire filter. You can read the more about it in the plugin readme page.

    Let me know if that works for you,

    Best,
    Bagus

    Thread Starter paxton111

    (@paxton111)

    /**
     * Change the token's expire value.
     *
     * @param int $expire The default "exp" value in timestamp.
     * @param int $issued_at The "iat" value in timestamp.
     *
     * @return int The "nbf" value.
     */
    add_filter(
        'jwt_auth_expire',
        function ( $expire, $issued_at ) {
            time() + (DAY_IN_SECONDS * 7)
            return $expire;
        },
        10,
        2
    );

    It should look like this? And how to set expiry date to be two years?
    And where do I need to add this code?

    Thanks

    • This reply was modified 1 year, 11 months ago by paxton111.
    Plugin Author Bagus

    (@contactjavas)

    Hi @paxton111 , the code above needs adjustment:

    
    /**
     * Change the token's expire value.
     *
     * @param int $expire The default "exp" value in timestamp.
     * @param int $issued_at The "iat" value in timestamp.
     *
     * @return int The "expire" value.
     */
    add_filter(
        'jwt_auth_expire',
        function ( $expire, $issued_at ) {
            // Set $expire to 2 years.
            $expire = time() + (DAY_IN_SECONDS * (2 * 365));
    
            return $expire;
        },
        10,
        2
    );
    

    Put this to functions.php in your theme. If it doesn’t work, create a plugin containing 1 file, activate it, and put your code there.

    Let me know if that works for you 🙂

    Best,
    Bagus

    Thread Starter paxton111

    (@paxton111)

    Thanks, I will test this out!

    Thread Starter paxton111

    (@paxton111)

    Hey there,

    So I noticed that the token is not valid anymore in Postman even tough I’ve set this expiration date to be two years.
    What could be the issue?
    Is there a way to test expiry date without waiting?

    thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Expiration date for token’ is closed to new replies.