How to build a plugin that supports authenticated POST requests to the REST API from external servers?

Answering my own question.

For plugin developers, the directive is to use current_user_can() in your code as usual in the REST endpoints, as Core does.

WordPress 5.4 does not support authenticated requests originated from outside WordPress to the REST API yet. But your clients can use plugins such as Basic Auth, OAuth2 or JWT to add that functionality.

The REST team in WordPress is working to add a built-in authentication method into Core, most likely, OAuth2. Now is May 01 2020. My blatant, probably wrong guess, is that this could be coming to Core in 12~ months or so.

2021 update

REST API authentication with Application Passwords was added in WordPress core on 5.6!

https://wordpress.org/support/wordpress-version/version-5-6/#rest-api-authentication-with-application-passwords

Leave a Comment