connections = $connections; } /** @return object|null The connection row, or null when unauthenticated. */ public function authenticate( WP_REST_Request $request ): ?object { $key_id = (string) $request->get_header( 'X-Shiftora-Key-Id' ); $token = $request->get_header( 'X-Shiftora-Token' ); if ( '' !== $key_id ) { // A hash is lower-case hex of fixed length; anything else cannot match a stored one. $connection = 1 === preg_match( '/\A[0-9a-f]{64}\z/', $key_id ) ? $this->connections->find_by_key_id( $key_id ) : null; } elseif ( ! empty( $token ) ) { $connection = $this->connections->find_by_token( $token ); } else { return null; } if ( null === $connection ) { return null; } if ( 'revoked' === $connection->status ) { return null; } $this->connections->update_last_ping( (int) $connection->id ); return $connection; } }