WordPress cookies based protection for the WordPress REST API
Introduction
Use this guide if you want to protect your WordPress REST API endpoints with a combination of a WordPress cookie and a nonce for delegated access. If you enable WPO365's WordPress cookie based endpoint protection for the WordPress REST API then applications requesting data from any of the protected endpoints will either receive a 401 (unauthorized) or 403 (forbidden) error, unless they present a valid WordPress authentication cookie and a valid WordPress REST nonce .
Please note
The nonce must be passed to the API via the X-WP-Nonce header and that the _wpnonce data parameter is not supported.
This article aims to explain the following steps needed to update the configuration of your WordPress website's App registration in Azure AD to be able to configure the Azure AD based protection for your WordPress REST API:
Before you start
- You are an Administrator for your WordPress website.
Enable WordPress cookie based endpoint protection
- Open a new browser tab and go to WP Admin > WPO365 > Integration.
- Scroll down to WordPress cookie based protection for the WordPress REST API.
- Check the option to Enable cookie based WordPress REST API protection.
- Protect an endpoint by entering the following details:
- The endpoint's path e.g. /wp-json/wp/v2/users/me. If you enter an incomplete path e.g. /wp-json/wp/v2 then be aware that all requests to endpoints starting with /wp-json/wp/v2 will be subject to the protection defined by this configuration
- The HTTP methods for which the protection should be activated as a comma separated string e.g. post or get, post.
- If you want to Block all other WordPress REST endpoints you can check the corresponding option.
- Click Save configuration.
Below is a screenshot of an exemplary WordPress cookie based protection for the WordPress REST API configuration.
Important
If you selected the Intranet Authentication scenario (on the plugin's Single Sign-on configuration page) then the plugin will - by default - block access to all your WordPress REST API endpoints. To work-around this, you must add the path of endpoints that you want to protect to the list of Pages freed from authentication (also on the plugin's Single Sign-on configuration page). Also refer to the online documentation for the Authentication scenario documentation.
Important
If you selected the Intranet Authentication scenario (on the plugin's Single Sign-on configuration page) then the plugin will - by default - block access to all your WordPress REST API endpoints. To work-around this, you must add the path of endpoints that you want to protect to the list of Pages freed from authentication (also on the plugin's Single Sign-on configuration page). Also refer to the online documentation for the Authentication scenario documentation.