WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: JSON API] How do I authenticate as a WP user to do a create_post? (5 posts)

  1. hyperink
    Member
    Posted 2 years ago #

    What's the simplest easiest way to authenticate so I have permissions to create a post using the JSON API plugin?

    I'm fine with using other plug-ins such as Authentication - http://www.hyperinkpress.com/wp-admin/network/plugin-install.php?tab=plugin-information&plugin=http-authentication&TB_iframe=true&width=640&height=611

    Whatever is easiest and I can use through Python.

  2. Marcel Bokhorst
    Member
    Posted 2 years ago #

    I am having the same question ...

  3. vbakare
    Member
    Posted 2 years ago #

    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....

  4. vbakare
    Member
    Posted 2 years ago #

    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

  5. michapixel
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic