
Trying to access your custom posttype through the WordPress rest-API, but want to make sure the session has the correct permissions? Well, according to the docs you could do this with Basic Authentication.
However it did not seem to work. I was trying the proof of concept with a request like this:
$url_test = 'https://yourtestwebsite.url/wp-json/wp/v2/yourcustomposttype';
$user = 'yourapiusername';
$pass = 'yourapiuserpassword';
$auth = base64_encode($user.':'.$pass);
$ctx = stream_context_create(array('http' => array('header' => 'Authorization: Basic '.$auth)));
$data = file_get_contents($url_test, false, $ctx);
Adding yourcustomposttype to the rest api is simple, but you can not add any permissions check. So I added an extra check for the correct permission first before adding the custom endpoint, like so:
Continue reading WordPress REST API Authentication



