Open psaikali opened 3 years ago
Hi @psaikali, you can use the request endpoint in wp like this:
//override for current user token generation
add_filter( 'authenticate', function($user, $name, $pwd){ return wp_get_current_user(); }, 999, 3);
//api call
$r = new WP_REST_Request( 'POST', '/jwt-auth/v1/token');
$response = rest_do_request( $r );
First of all, thank you for developing this plugin! It's really great. I'm using it to authenticate users from a React Native app.
I'm creating my own API route for that, where I directly call the
generate_token()
method on theJWTAuth\Auth
class, like so:So far so good, but I'm wondering if it would be safer and more practical for everybody if we had access to a basic function to generate the token, instead of instantiating the class and calling the right method. Maybe something like
jwtauth_generate_token( $user, false )
.That way, it's update-proof: if something changes (class name, method, parameters), we make sure to reflect these changes in the publicly available function, so we ensure long-term compat.
What do you think?
I can take care of creating such a function and add a PR if necessary.