protected function loadAccessTokenByAuthenticatingUser(callable $getAuthCode)
    {
        // Getting an auth code
        try {
            $authUrl = $this->client->createAuthUrl();
        } catch (\Exception $exception) {
            throw new \RuntimeException(
                'Couldn\'t create an authentication URL: '.rtrim($exception->getMessage(), '.').'. ' .
                'Maybe there is a problem with the secret file.'
            );
        }

        $authCode = $getAuthCode($authUrl);
        if (!is_string($authCode) || $authCode === '') {
            throw new \LogicException('The $getAuthCode function has returned a not-string or an empty string');
        }

        // Authenticating
        $this->logger->info('Sending the authentication code to Google');
        try {
            $accessToken = $this->client->fetchAccessTokenWithAuthCode($authCode);
        } catch (\Exception $exception) {
            throw new \RuntimeException(
                'Failed to send the authentication code to Google: '.rtrim($exception->getMessage(), '.').'. ' .
                'Maybe there is a problem with the secret file.'
            );
        }
        if (isset($accessToken['error'])) {
            throw new \RuntimeException('Google has declined the auth code: '.($accessToken['error_description'] ?? '(no message)'));
        }

        $this->logger->notice('Authenticated successfully');
    }
protected function loadAccessTokenByAuthenticatingUser(callable $getAuthCode)
    {
        // Getting an auth code
        try {
            $authUrl = $this->client->createAuthUrl();
        } catch (\Exception $exception) {
            throw new \RuntimeException(
                'Couldn\'t create an authentication URL: '.rtrim($exception->getMessage(), '.').'. ' .
                'Maybe there is a problem with the secret file.'
            );
        }

        $authCode = $getAuthCode($authUrl);
        if (!is_string($authCode) || $authCode === '') {
            throw new \LogicException('The $getAuthCode function has returned a not-string or an empty string');
        }

        // Authenticating
        $this->logger->info('Sending the authentication code to Google');
        try {
            $accessToken = $this->client->fetchAccessTokenWithAuthCode($authCode);
        } catch (\Exception $exception) {
            throw new \RuntimeException(
                'Failed to send the authentication code to Google: '.rtrim($exception->getMessage(), '.').'. ' .
                'Maybe there is a problem with the secret file.'
            );
        }
        if (isset($accessToken['error'])) {
            throw new \RuntimeException('Google has declined the auth code: '.($accessToken['error_description'] ?? '(no message)'));
        }

        $this->logger->notice('Authenticated successfully');
    }
protected function loadAccessTokenByAuthenticatingUser ( callable $ getAuthCode ) { // Getting an auth code try { $ authUrl = $ this -> client -> createAuthUrl ( ) ; } catch ( \ Exception $ exception ) { throw new \ RuntimeException ( 'Couldn\'t create an authentication URL: ' . rtrim ( $ exception -> getMessage ( ) , '.' ) . '. ' . 'Maybe there is a problem with the secret file.' ) ; } $ authCode = $ getAuthCode ( $ authUrl ) ; if ( ! is_string ( $ authCode ) || $ authCode === '' ) { throw new \ LogicException ( 'The $getAuthCode function has returned a not-string or an empty string' ) ; } // Authenticating $ this -> logger -> info ( 'Sending the authentication code to Google' ) ; try { $ accessToken = $ this -> client -> fetchAccessTokenWithAuthCode ( $ authCode ) ; } catch ( \ Exception $ exception ) { throw new \ RuntimeException ( 'Failed to send the authentication code to Google: ' . rtrim ( $ exception -> getMessage ( ) , '.' ) . '. ' . 'Maybe there is a problem with the secret file.' ) ; } if ( isset ( $ accessToken [ 'error' ] ) ) { throw new \ RuntimeException ( 'Google has declined the auth code: ' . ( $ accessToken [ 'error_description' ] ?? '(no message)' ) ) ; } $ this -> logger -> notice ( 'Authenticated successfully' ) ; }
Gets an access token using the interactive authentication process and saves it to the current Google client

@param callable $getAuthCode A function which asks the user for an auth code. Takes an authentication url (the
user must open it in browser) and returns an auth code.
@param string|null $tokenFilePath
@throws \RuntimeException If the authentication fails
@throws \LogicException If the $getAuthCode function returns not a filled string
Gets an access token using the interactive authentication process and saves it to the current Google client