• Resolved chetan.g

    (@chetang-1)


    I want to call the method of validate_auth_cookie of user controller from any other controller. can please let me know any example for this, I want to call some method of a controller after just validate the authentication.

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

    (@parorrey)

    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.

    Thread Starter chetan.g

    (@chetang-1)

    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.

    Plugin Author Ali Qureshi

    (@parorrey)

    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/

    Thread Starter chetan.g

    (@chetang-1)

    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.

    Plugin Author Ali Qureshi

    (@parorrey)

    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');

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Call validation from other controller’ is closed to new replies.