public function authenticate(
        string $gApiOAuthSecretFile,
        ?string $gApiAccessTokenFile,
        array $scopes,
        callable $getAuthCode,
        bool $forceAuthenticate = false
    ) {
        $this->client->setApplicationName('XmlSquad Tools');
        $this->client->setScopes($scopes);
        $this->client->setAccessType('offline');
        $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
        $this->loadClientSecretFromFile($gApiOAuthSecretFile);

        // Getting an access token
        if ($gApiAccessTokenFile !== null && !$forceAuthenticate && is_file($gApiAccessTokenFile)) {
            $this->loadAccessTokenFromFile($gApiAccessTokenFile);
        } else {
            $this->loadAccessTokenByAuthenticatingUser($getAuthCode);

            if ($gApiAccessTokenFile !== null) {
                $this->saveCurrentAccessTokenToFile($gApiAccessTokenFile);
                $this->logger->info('So subsequent executions will not prompt for authorization');
            }
        }

        if ($this->refreshAccessTokenIfRequired()) {
            if ($gApiAccessTokenFile !== null) {
                $this->saveCurrentAccessTokenToFile($gApiAccessTokenFile);
            }
        }

        $this->logger->info('The Google authentication is completed');
    }
public function authenticate(
        string $gApiOAuthSecretFile,
        ?string $gApiAccessTokenFile,
        array $scopes,
        callable $getAuthCode,
        bool $forceAuthenticate = false
    ) {
        $this->client->setApplicationName('XmlSquad Tools');
        $this->client->setScopes($scopes);
        $this->client->setAccessType('offline');
        $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
        $this->loadClientSecretFromFile($gApiOAuthSecretFile);

        // Getting an access token
        if ($gApiAccessTokenFile !== null && !$forceAuthenticate && is_file($gApiAccessTokenFile)) {
            $this->loadAccessTokenFromFile($gApiAccessTokenFile);
        } else {
            $this->loadAccessTokenByAuthenticatingUser($getAuthCode);

            if ($gApiAccessTokenFile !== null) {
                $this->saveCurrentAccessTokenToFile($gApiAccessTokenFile);
                $this->logger->info('So subsequent executions will not prompt for authorization');
            }
        }

        if ($this->refreshAccessTokenIfRequired()) {
            if ($gApiAccessTokenFile !== null) {
                $this->saveCurrentAccessTokenToFile($gApiAccessTokenFile);
            }
        }

        $this->logger->info('The Google authentication is completed');
    }
public function authenticate ( string $ gApiOAuthSecretFile , ? string $ gApiAccessTokenFile , array $ scopes , callable $ getAuthCode , bool $ forceAuthenticate = false ) { $ this -> client -> setApplicationName ( 'XmlSquad Tools' ) ; $ this -> client -> setScopes ( $ scopes ) ; $ this -> client -> setAccessType ( 'offline' ) ; $ this -> client -> setRedirectUri ( 'urn:ietf:wg:oauth:2.0:oob' ) ; $ this -> loadClientSecretFromFile ( $ gApiOAuthSecretFile ) ; // Getting an access token if ( $ gApiAccessTokenFile !== null && ! $ forceAuthenticate && is_file ( $ gApiAccessTokenFile ) ) { $ this -> loadAccessTokenFromFile ( $ gApiAccessTokenFile ) ; } else { $ this -> loadAccessTokenByAuthenticatingUser ( $ getAuthCode ) ; if ( $ gApiAccessTokenFile !== null ) { $ this -> saveCurrentAccessTokenToFile ( $ gApiAccessTokenFile ) ; $ this -> logger -> info ( 'So subsequent executions will not prompt for authorization' ) ; } } if ( $ this -> refreshAccessTokenIfRequired ( ) ) { if ( $ gApiAccessTokenFile !== null ) { $ this -> saveCurrentAccessTokenToFile ( $ gApiAccessTokenFile ) ; } } $ this -> logger -> info ( 'The Google authentication is completed' ) ; }
Authenticates the client by asking user to go to the URL and paste the code given by Google

@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 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 bool $forceAuthenticate If true, the user will be asked to authenticate even if the access token exist
@throws \RuntimeException If the authentication failed
@throws \LogicException If the $getAuthCode function returns not a filled string
Authenticates the client by asking user to go to the URL and paste the code given by Google