Solution:
I was facing a similar issue and solved it with the following approach:
- Use WordPress OAuth Server plug-in instead of the one suggested by the WP REST API docs.
- Enable “User Credentials” grant type in the settings.
- Follow the directions for using the Postman tool to get the idea of the flow for obtaining the OAuth access token.
I don’t have a PHP code sample as I’m working in JavaScript. However, the steps are fairly easy:
- Issue a POST request to yourserver.com?oauth=token (step 3 in the list above)
- Append ?access_token=xxxxxx (xxxxxx being the access token) to all subsequent requests to the API endpoints that require privileged access.