public function authenticateFromCommand(
        InputInterface $input,
        OutputInterface $output,
        string $gApiOAuthSecretFile,
        ?string $gApiAccessTokenFile,
        array $scopes,
        bool $forceAuthenticate = false
    ): bool {
        try {
            $this->authenticate(
                $gApiOAuthSecretFile,
                $gApiAccessTokenFile,
                $scopes,
                function ($authURL) use ($input, $output) {
                    $output->writeln('<info>You need to authenticate to your Google account to proceed</info>');
                    $output->writeln('Open the following URL in a browser, get an auth code and paste it below:');
                    $output->writeln('');
                    $output->writeln($authURL, OutputInterface::OUTPUT_PLAIN);
                    $output->writeln('');

                    $question = new Question('Auth code: ');
                    $question->setValidator(function ($answer) {
                        $answer = trim($answer);

                        if ($answer === '') {
                            throw new \RuntimeException('Please enter an auth code');
                        }

                        return $answer;
                    });
                    return (new QuestionHelper())->ask($input, $output, $question);
                },
                $forceAuthenticate
            );
        } catch (\RuntimeException $exception) {
            $output->writeln('<error>Failed to authenticate to Google: '.OutputFormatter::escape($exception->getMessage()).'</error>');
            return false;
        }

        return true;
    }
public function authenticateFromCommand(
        InputInterface $input,
        OutputInterface $output,
        string $gApiOAuthSecretFile,
        ?string $gApiAccessTokenFile,
        array $scopes,
        bool $forceAuthenticate = false
    ): bool {
        try {
            $this->authenticate(
                $gApiOAuthSecretFile,
                $gApiAccessTokenFile,
                $scopes,
                function ($authURL) use ($input, $output) {
                    $output->writeln('<info>You need to authenticate to your Google account to proceed</info>');
                    $output->writeln('Open the following URL in a browser, get an auth code and paste it below:');
                    $output->writeln('');
                    $output->writeln($authURL, OutputInterface::OUTPUT_PLAIN);
                    $output->writeln('');

                    $question = new Question('Auth code: ');
                    $question->setValidator(function ($answer) {
                        $answer = trim($answer);

                        if ($answer === '') {
                            throw new \RuntimeException('Please enter an auth code');
                        }

                        return $answer;
                    });
                    return (new QuestionHelper())->ask($input, $output, $question);
                },
                $forceAuthenticate
            );
        } catch (\RuntimeException $exception) {
            $output->writeln('<error>Failed to authenticate to Google: '.OutputFormatter::escape($exception->getMessage()).'</error>');
            return false;
        }

        return true;
    }
public function authenticateFromCommand ( InputInterface $ input , OutputInterface $ output , string $ gApiOAuthSecretFile , ? string $ gApiAccessTokenFile , array $ scopes , bool $ forceAuthenticate = false ) : bool { try { $ this -> authenticate ( $ gApiOAuthSecretFile , $ gApiAccessTokenFile , $ scopes , function ( $ authURL ) use ( $ input , $ output ) { $ output -> writeln ( '<info>You need to authenticate to your Google account to proceed</info>' ) ; $ output -> writeln ( 'Open the following URL in a browser, get an auth code and paste it below:' ) ; $ output -> writeln ( '' ) ; $ output -> writeln ( $ authURL , OutputInterface :: OUTPUT_PLAIN ) ; $ output -> writeln ( '' ) ; $ question = new Question ( 'Auth code: ' ) ; $ question -> setValidator ( function ( $ answer ) { $ answer = trim ( $ answer ) ; if ( $ answer === '' ) { throw new \ RuntimeException ( 'Please enter an auth code' ) ; } return $ answer ; } ) ; return ( new QuestionHelper ( ) ) -> ask ( $ input , $ output , $ question ) ; } , $ forceAuthenticate ) ; } catch ( \ RuntimeException $ exception ) { $ output -> writeln ( '<error>Failed to authenticate to Google: ' . OutputFormatter :: escape ( $ exception -> getMessage ( ) ) . '</error>' ) ; return false ; } return true ; }
A helper for a Symfony Console command. Authenticates the client by asking user to go to the URL and paste the
code given by Google. In case of a failed authentication prints a message to the console.

@param InputInterface $input The command input
@param OutputInterface $output The command output
@param string $gApiOAuthSecretFile Path to the API client secret JSON file
@param string|null $gApiAccessTokenFile Path to the access token JSON file. Optional. The file may not exist.
@param string[] $scopes The list of the required authenticaton scopes,
e.g. [\Google_Service_Drive::DRIVE_READONLY, \Google_Service_Sheets::SPREADSHEETS_READONLY]
@param bool $forceAuthenticate If true, the user will be asked to authenticate even if the access token exist
@return bool True if the user is authenticated successfully
A helper for a Symfony Console command . Authenticates the client by asking user to go to the URL and paste the code given by Google . In case of a failed authentication prints a message to the console .