Tmeister / wp-api-jwt-auth

A simple plugin to add JSON Web Token (JWT) Authentication to WP REST API
GNU General Public License v2.0
549 stars 159 forks source link

How to set jwt_auth_expire #214

Open MaurizioB84 opened 3 years ago

MaurizioB84 commented 3 years ago

Hello, I understand we can extend or reduce the validity time of the token generated, but I don't understand in which way I can set it.

After some tests with a short validity the token still works. can you please give me an example of right request? I use postman for that with in the body username and password and standard header parameters + jwt_auth_expire with value in second.

pesseba commented 3 years ago

Hi, the jwt_auth_expire can't be set by post parameter, It's a filter for plugins or themes. You shoud add some custom script for this. Example:

add_filter('jwt_auth_expire', 'on_jwt_expire_token',10,1);  
public function on_jwt_expire_token($exp){      
    $days = 182;
    $exp = time() + (86400 * $days);            
    return $exp;
}
MostafaBelihi commented 2 years ago

Hi, @pesseba where can I add this custom script? I'm not a PHP developer but I use WooCommerce for my app.

I was able to edit the main PHP file at jwt-authentication-for-wp-rest-api/public/class-jwt-auth-public.php to add some more properties I need to the JWT endpoint response. I also can change expiration time of a JWT from this place. But this means that when I update the plugin, all my changes are gone.

How and where can I add this custom script? And is there a better way to customize JSON response of the JWT endpoint, like adding Issue and Expiry times of a JWT, other than modifying their main PHP file?

pesseba commented 2 years ago

The best way is to add a simple plugin. I create one for this, you can download here: jwt-auth-expire.zip

MostafaBelihi commented 2 years ago

Thanks for your help.

afrascona commented 1 year ago

Any way I can deauthorize an issued token please? Perhaps pass this expire hook a function instead?