@@ -241,7 +241,21 @@ public function authenticate( $result ) {
241241 // Validate the bearer token.
242242 $ token = $ this ->validate_token ();
243243 if ( is_wp_error ( $ token ) ) {
244- return $ token ;
244+ /**
245+ * Filter the response when a token is invalid.
246+ *
247+ * By default an authentication error will be returned. This filter
248+ * allows us to modify that response ignoring an invalid token,
249+ * allowing the REST API response to continue, making JWT auth
250+ * optional.
251+ *
252+ * @param object|WP_Error $token Return the JSON Web Token object,
253+ * or WP_Error on failure.
254+ * @param mixed $result Result of any other
255+ * authentication errors.
256+ * @return mixed
257+ */
258+ return apply_filters ( 'rest_authentication_invalid_token ' , $ token , $ result );
245259 }
246260
247261 // If it's a wp_user based token, set the current user.
@@ -382,7 +396,7 @@ public function require_token() {
382396
383397 /**
384398 * GET requests do not typically require authentication, but if the
385- * Authorization header is provided, we will use it. WHat 's happening
399+ * Authorization header is provided, we will use it. What 's happening
386400 * here is that `WP_REST_Token::get_auth_header` returns the bearer
387401 * token or a `WP_Error`. So if we have an error then we can safely skip
388402 * the GET request.
0 commit comments