Yoast\WP\SEO\MyYoast_Client\Application

OAuth_Callback_Handler::resolve │ private │ Yoast 1.0

Performs the callback orchestration and classifies the result.

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

Хуков нет.

Возвращает

Callback_Outcome. The outcome of the callback.

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

// private - только в коде основоного (родительского) класса
$result = $this->resolve( $user_id, $code, $state, $error ): Callback_Outcome;
$user_id(int) (обязательный)
The WordPress user ID the flow belongs to.
$code(строка) (обязательный)
The authorization code from the callback (empty if absent).
$state(строка) (обязательный)
The state parameter from the callback (empty if absent).
$error(строка) (обязательный)
The provider error code from the callback (empty if none).

Код OAuth_Callback_Handler::resolve() Yoast 28.9

private function resolve( int $user_id, string $code, string $state, string $error ): Callback_Outcome {
	if ( $error !== '' ) {
		// The provider returned an error: drop the pending flow so it can't be resumed.
		$this->auth_code_handler->discard_flow_state( $user_id );
		return Callback_Outcome::provider_error( $error );
	}

	if ( $code === '' || $state === '' ) {
		// Stale bookmark or someone hitting the callback URL directly: not a real callback.
		return Callback_Outcome::no_op();
	}

	try {
		$this->myyoast_client->exchange_authorization_code( $user_id, $code, $state );
	} catch ( Token_Request_Failed_Exception $e ) {
		return Callback_Outcome::exchange_error( $e->get_error_code() );
	} catch ( Throwable $e ) {
		$this->logger->error(
			'Unexpected error during MyYoast OAuth callback exchange for user {user_id}: {error}',
			[
				'user_id' => $user_id,
				'error'   => $e->getMessage(),
			],
		);
		// No OAuth response was produced, so there is no native error code to surface.
		return Callback_Outcome::exchange_error( null );
	}

	return Callback_Outcome::success();
}