Hi,
This is how you can authenticate user for valid cookie in any other method:
$user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
If cookie is correct, you get $user_id, otherwise false.
Thanks ali for the answer, could you please tell me one more thing that, I want to generate the token from any other controller as well? In that controller method I got the username and password of the user for login and registration.
do you want to generate ‘cookie’ or ‘nonce’? What do you mean by token?
You just need to use /api/user/generate_auth_cookie/ and /api/get_nonce/
Ohh I mean to say generate cookie which I used as a token in response sending after authentication gets successful and when ever api hits any other method of any other controller need to check the cookie or token, if it will verified proceed further, otherwise show error message.
SO I want to generate the cookie without calling /api/user/generate_auth_cookie/ , I want to generate in a different controller method. now I hope you got my point.
if you generate the cookie with this Auth or User controller, it will work for all controllers. it just has to be valid.
you validate cookie calling this in every controller:
$user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');