在Wordpress中设置JWT令牌到期日期

时间:2020-08-26 13:33:51

标签: php wordpress jwt jwt-auth

我想将JWT令牌的到期日期设置为自发行之日起两年。

我下面有这段代码,并将其放在Wordpress中的function.php中,但由于401错误,JWT令牌似乎很快过期,因为它不允许我发出请求:

/**
 * 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
);

0 个答案:

没有答案