Yoast\WP\SEO\MyYoast_Client\User_Interface

Management_Route::authorize │ public │ Yoast 1.0

POST /myyoast/authorize — starts the authorization-code flow and returns the URL the browser should be sent to.

Completing the round-trip verifies that the site's redirect URI is reachable and that the user is who they claim to be. The client resolves the redirect URI itself, and the authorization-code handler marks it validated once the returning code is exchanged.

The optional return_url is where the browser is sent once the flow completes; the caller supplies it because the flow can be started from different admin pages. It is validated against the site's own host, so an off-site or tampered value is dropped (and the callback then surfaces a standalone outcome rather than redirecting anywhere).

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

Хуков нет.

Возвращает

WP_REST_Response.

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

$Management_Route = new Management_Route();
$Management_Route->authorize( $request ): WP_REST_Response;
$request(WP_REST_Request) (обязательный)
The REST request.

Код Management_Route::authorize() Yoast 28.9

public function authorize( WP_REST_Request $request ): WP_REST_Response {
	if ( $this->client_registration->get_registered_client() === null ) {
		return $this->error_response( 'registration_gone' );
	}

	$user_id = \get_current_user_id();
	if ( $user_id <= 0 ) {
		// Return HTTP 200 with the error_code in the body like every other failure here:
		// api-fetch rejects non-2xx, which would mask invalid_user as a generic unexpected_error.
		return $this->error_response( 'invalid_user' );
	}

	$return_url = $this->resolve_return_url( $request->get_param( 'return_url' ) );

	try {
		$authorize_url = $this->myyoast_client->get_authorization_url(
			$user_id,
			[ 'openid' ],
			null,
			$return_url,
		);
	} catch ( Authorization_Flow_Exception $e ) {
		return $this->error_response( 'registration_failed', $e );
	} catch ( Invalid_Resource_Exception $e ) {
		return $this->handle_exception( $e );
	}

	$body = [
		'authorize_url' => $authorize_url,
		'status'        => $this->status_presenter->present(),
	];

	return new WP_REST_Response( $body, 200 );
}