Support » Plugins » [Plugin: JSON API] How do I authenticate as a WP user to do a create_post?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am having the same question …

    Anybody have solution for this? I am trying to create/submit response to post using json api and it is not allowing me to do so. Authentication is required.

    Help please….

    Ok. I got it working. I modified the post.php controller file to authenticate using user name password.
    I wanted to create post from my intranet J2EE application , and was not allowed to retrieve actual passwords of the User from Active Directory.
    So I created a Super User who has access to create post just for authentication and modified the authenticate() method from post.php to read one more parameter ‘wpAuthUser’ and let the ‘Author’ parameter used for post author only.

    private function authenticate() {
    global $json_api;
    if ($json_api->query->wpUser && $json_api->query->user_password) {
    $user = wp_signon(array(‘user_login’ => $json_api->query->wpUser, ‘user_password’ => $json_api->query->user_password));
    if (get_class($user) == ‘WP_Error’) {
    $json_api->error($user->errors);
    } else {
    if (!user_can($user->ID,’edit_posts’)) {
    $json_api->error(“You need to login with a user capable of creating posts.”);
    }
    }
    } else {
    if (!current_user_can(‘edit_posts’)) {
    $json_api->error(“You need to login with a user capable of creating posts.”);
    }
    }
    }

    you can also refer below link for original concept.
    https://github.com/dphiffer/wp-json-api/pull/3

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: JSON API] How do I authenticate as a WP user to do a create_post?’ is closed to new replies.