hyperink
Member
Posted 6 months 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.
I am having the same question ...
vbakare
Member
Posted 4 months 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....
vbakare
Member
Posted 4 months 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