Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/tests for Data and Verify #81

Merged
merged 17 commits into from
Jun 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update authenticate function to match rest_authentication_errors
…filter
  • Loading branch information
BrianHenryIE committed Jun 13, 2024
commit 4139a59b3b7f57c7b7c3270315cece376b76ddb6
19 changes: 10 additions & 9 deletions includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function start(): void {

// Delays our primary module setup until init
add_action( 'init', array( $this, 'init' ) );
add_action( 'rest_authentication_errors', array( $this, 'authenticate' ) );
add_filter( 'rest_authentication_errors', array( $this, 'authenticate' ) );

// If we ever get a 401 response from the Hiive API, delete the token.
add_filter(
Expand Down Expand Up @@ -102,24 +102,25 @@ public function init(): void {
* Authenticate incoming REST API requests.
*
* @hooked rest_authentication_errors
*
* @param bool|null|\WP_Error $errors
*
* @return bool|null|\WP_Error
* @see WP_REST_Server::check_authentication()
*
* @used-by ConnectSite::verifyToken() in Hiive.
*
* @param bool|null|\WP_Error $status
*
* @return bool|null|\WP_Error
*/
public function authenticate( $status ) {
public function authenticate( $errors ) {

// Make sure there wasn't a different authentication method used before this
if ( ! is_null( $status ) ) {
return $status;
if ( ! is_null( $errors ) ) {
return $errors;
}

// Make sure this is a REST API request
if ( ! defined( 'REST_REQUEST' ) || ! constant( 'REST_REQUEST' ) ) {
return $status;
return $errors;
}

// If no auth header included, bail to allow a different auth method
Expand Down Expand Up @@ -165,6 +166,6 @@ public function authenticate( $status ) {
}

// Don't return false, since we could be interfering with a basic auth implementation.
return null;
return $errors;
}
}