public function isOAuthAuthenticated(ServerRequestInterface $request)
    {
        $queryParams = $request->getQueryParams();
        $code = $queryParams[GoogleClient::KEY_CODE] ?? null;
        $state = $queryParams[GoogleClient::KEY_STATE] ?? null;

        $this->logger->debug(
            json_encode(
                [
                    'Incoming authorization code: ' . $code,
                    'Incoming state: ' . $state,
                    'Redirect uri: ' . $this->getConfig('redirectUri'),
                ]
            )
        );

        if ($this->getSession($request)->get(GoogleClient::KEY_STATE) != $state) {
            $this->logger->debug("Invalid incoming state");

            return false;
        }

        if (!$this->googleClient->authenticateWithAuthCode($code)) {
            $this->logger->debug("Authentication with authorization code failed");

            return false;
        }

        return true;
    }