# ivyforms/1.5.1/backend/src/Controllers/GoogleSheets/GoogleSheetsConnectController.php

The Innovative Form Builder – IvyForms, version 1.5.1. 50 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/1.5.1/code/backend/src/Controllers/GoogleSheets/GoogleSheetsConnectController.php
- Raw: https://pluginprobe.com/plugins/ivyforms/1.5.1/raw/backend/src/Controllers/GoogleSheets/GoogleSheetsConnectController.php
- Modified: 2026-07-15T16:27:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/1.5.1/code/backend/src/Controllers/GoogleSheets/GoogleSheetsConnectController.php#L10-L20`.

```php
<?php

namespace IvyForms\Controllers\GoogleSheets;

use IvyForms\Common\Exceptions\ForbiddenException;
use IvyForms\Common\Exceptions\InvalidArgumentException;
use IvyForms\Common\Sanitizer\Sanitizer;
use IvyForms\Controllers\Controller;
use IvyForms\Services\GoogleSheets\Helpers\GoogleSheetsOAuthStateHelper;
use IvyForms\Services\GoogleSheets\GoogleSheetsService;
use WP_REST_Request;
use WP_REST_Response;

class GoogleSheetsConnectController extends Controller
{
    private GoogleSheetsService $googleSheetsService;

    public function __construct(GoogleSheetsService $googleSheetsService)
    {
        $this->googleSheetsService = $googleSheetsService;
    }

    /**
     * @throws ForbiddenException
     * @throws InvalidArgumentException
     */
    protected function handle(WP_REST_Request $data): WP_REST_Response
    {
        Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));

        if (!$this->googleSheetsService->isMiddlewareReachable()) {
            throw new InvalidArgumentException(
                $this->googleSheetsService->getMiddlewareUnreachableMessage()
            );
        }

        $authUrl = $this->googleSheetsService->createAuthUrl(GoogleSheetsOAuthStateHelper::createState());

        if ($authUrl === '') {
            throw new InvalidArgumentException(
                $this->googleSheetsService->getOAuthNotConfiguredMessage()
            );
        }

        return new WP_REST_Response([
            'auth_url' => $authUrl,
        ], 200);
    }
}

```
