Yoast\WP\SEO\MyYoast_Client\Infrastructure\Registration
Client_Registration::update_redirect_uris
Updates the registered redirect URIs in place (RFC 7592 PUT).
Preserves the client_id, registration access token, and key pair. Verification state for URIs that remain in the set is preserved; URIs no longer present are dropped.
Метод класса: Client_Registration{}
Хуков нет.
Возвращает
Registered_Client. The updated credentials.
Использование
// private - только в коде основоного (родительского) класса $result = $this->update_redirect_uris( $redirect_uris ): Registered_Client;
- $redirect_uris(string[]) (обязательный)
- The new exact set of redirect URIs.
Код Client_Registration::update_redirect_uris() Client Registration::update redirect uris Yoast 28.3
private function update_redirect_uris( array $redirect_uris ): Registered_Client {
$registered_client = $this->get_registered_client();
if ( $registered_client === null ) {
throw new Registration_Failed_Exception( 'Not registered.' );
}
// Per RFC 7592 §2.2, server-assigned fields MUST NOT be included; keep the existing key pair.
$request_body = $this->build_update_request_body( $registered_client->get_metadata() );
$request_body['redirect_uris'] = \array_values( $redirect_uris );
$request_body['software_statement'] = $this->issuer_config->get_software_statement();
// phpcs:ignore Yoast.Yoast.JsonEncodeAlternative.Found -- Encoding for HTTP request body, not user-facing output.
$json = \wp_json_encode( $request_body );
if ( $json === false ) {
throw new Registration_Failed_Exception( 'Failed to JSON-encode registration request body.' );
}
$result = $this->http_client->authenticated_request(
'PUT',
$registered_client->get_registration_client_uri(),
$registered_client->get_registration_access_token(),
Auth_Token_Type::BEARER,
[
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'body' => $json,
'timeout' => 15,
],
);
if ( $result->get_status() === 401 || $result->get_status() === 404 ) {
$this->logger->warning( 'Registration is no longer valid on update (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 update was rate-limited (HTTP 429).' );
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
throw new Rate_Limited_Exception( 'Registration update 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( 'Redirect URI update 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( 'Redirect URI update returned invalid response.' );
}
return $this->store_credentials( $body );
}