Yoast\WP\SEO\MyYoast_Client\Infrastructure\Registration

Client_Registration::read_registration │ public │ Yoast 1.0

Reads the current client registration from the server (RFC 7592 GET).

Метод класса: Client_Registration{}

Хуков нет.

Возвращает

array<string, string|string[]>. The registration metadata.

Использование

$Client_Registration = new Client_Registration();
$Client_Registration->read_registration(): array;

Код Client_Registration::read_registration() Yoast 28.9

public function read_registration(): array {
	$registered_client = $this->get_registered_client();
	if ( $registered_client === null ) {
		throw new Registration_Failed_Exception( 'Not registered.' );
	}

	$result = $this->http_client->authenticated_request(
		'GET',
		$registered_client->get_registration_client_uri(),
		$registered_client->get_registration_access_token(),
		Auth_Token_Type::BEARER,
		[
			'timeout' => 10,
			'headers' => [ 'Accept' => 'application/json' ],
		],
	);

	if ( $result->is_transport_failure() ) {
		$error_message = (string) $result->get_body_value( 'error_description', '' );
		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
		throw new Registration_Failed_Exception( 'Failed to read registration: ' . $error_message );
	}

	if ( $result->get_status() === 401 || $result->get_status() === 404 ) {
		$this->logger->warning( 'Registration is no longer valid (HTTP {status}), clearing local registration.', [ 'status' => $result->get_status() ] );
		$this->forget_registration();
		throw new Registration_Not_Found_Exception(
			// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
			'Registration is no longer valid (HTTP ' . $result->get_status() . ').',
		);
	}

	if ( $result->get_status() === 429 ) {
		$this->logger->warning( 'Registration read was rate-limited (HTTP 429).' );
		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
		throw new Rate_Limited_Exception( 'Registration read was rate-limited (HTTP 429).', $this->get_retry_after_seconds( $result ) );
	}

	if ( ! $result->is_successful() ) {
		$error_message = (string) $result->get_body_value( 'error_description', $result->get_body_value( 'error', '' ) );
		throw new Registration_Failed_Exception(
			// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
			\sprintf( 'Registration read returned HTTP %d: %s', $result->get_status(), $error_message ),
		);
	}

	$body = $result->get_body();
	if ( ! \is_array( $body ) || empty( $body['client_id'] ) ) {
		throw new Registration_Failed_Exception( 'Invalid response from registration endpoint.' );
	}

	// The server is authoritative: heal local data that has drifted from it (for example when a
	// site migration rewrote the stored redirect URIs directly in the database, bypassing the
	// registration round-trip). The GET body carries no RAT, so store_credentials preserves the
	// stored one.
	$this->store_credentials( $body );

	return $body;
}