public function setAuthConfig($config)
  {
    if (is_string($config)) {
      if (!file_exists($config)) {
        throw new InvalidArgumentException(sprintf('file "%s" does not exist', $config));
      }

      $json = file_get_contents($config);

      if (!$config = json_decode($json, true)) {
        throw new LogicException('invalid json for auth config');
      }
    }

    $key = isset($config['installed']) ? 'installed' : 'web';
    if (isset($config['type']) && $config['type'] == 'service_account') {
      // application default credentials
      $this->useApplicationDefaultCredentials();

      // set the information from the config
      $this->setClientId($config['client_id']);
      $this->config['client_email'] = $config['client_email'];
      $this->config['signing_key'] = $config['private_key'];
      $this->config['signing_algorithm'] = 'HS256';
    } elseif (isset($config[$key])) {
      // old-style
      $this->setClientId($config[$key]['client_id']);
      $this->setClientSecret($config[$key]['client_secret']);
      if (isset($config[$key]['redirect_uris'])) {
        $this->setRedirectUri($config[$key]['redirect_uris'][0]);
      }
    } else {
      // new-style
      $this->setClientId($config['client_id']);
      $this->setClientSecret($config['client_secret']);
      if (isset($config['redirect_uris'])) {
        $this->setRedirectUri($config['redirect_uris'][0]);
      }
    }
  }
public function setAuthConfig($config)
  {
    if (is_string($config)) {
      if (!file_exists($config)) {
        throw new InvalidArgumentException(sprintf('file "%s" does not exist', $config));
      }

      $json = file_get_contents($config);

      if (!$config = json_decode($json, true)) {
        throw new LogicException('invalid json for auth config');
      }
    }

    $key = isset($config['installed']) ? 'installed' : 'web';
    if (isset($config['type']) && $config['type'] == 'service_account') {
      // application default credentials
      $this->useApplicationDefaultCredentials();

      // set the information from the config
      $this->setClientId($config['client_id']);
      $this->config['client_email'] = $config['client_email'];
      $this->config['signing_key'] = $config['private_key'];
      $this->config['signing_algorithm'] = 'HS256';
    } elseif (isset($config[$key])) {
      // old-style
      $this->setClientId($config[$key]['client_id']);
      $this->setClientSecret($config[$key]['client_secret']);
      if (isset($config[$key]['redirect_uris'])) {
        $this->setRedirectUri($config[$key]['redirect_uris'][0]);
      }
    } else {
      // new-style
      $this->setClientId($config['client_id']);
      $this->setClientSecret($config['client_secret']);
      if (isset($config['redirect_uris'])) {
        $this->setRedirectUri($config['redirect_uris'][0]);
      }
    }
  }
public function setAuthConfig ( $ config ) { if ( is_string ( $ config ) ) { if ( ! file_exists ( $ config ) ) { throw new InvalidArgumentException ( sprintf ( 'file "%s" does not exist' , $ config ) ) ; } $ json = file_get_contents ( $ config ) ; if ( ! $ config = json_decode ( $ json , true ) ) { throw new LogicException ( 'invalid json for auth config' ) ; } } $ key = isset ( $ config [ 'installed' ] ) ? 'installed' : 'web' ; if ( isset ( $ config [ 'type' ] ) && $ config [ 'type' ] == 'service_account' ) { // application default credentials $ this -> useApplicationDefaultCredentials ( ) ; // set the information from the config $ this -> setClientId ( $ config [ 'client_id' ] ) ; $ this -> config [ 'client_email' ] = $ config [ 'client_email' ] ; $ this -> config [ 'signing_key' ] = $ config [ 'private_key' ] ; $ this -> config [ 'signing_algorithm' ] = 'HS256' ; } elseif ( isset ( $ config [ $ key ] ) ) { // old-style $ this -> setClientId ( $ config [ $ key ] [ 'client_id' ] ) ; $ this -> setClientSecret ( $ config [ $ key ] [ 'client_secret' ] ) ; if ( isset ( $ config [ $ key ] [ 'redirect_uris' ] ) ) { $ this -> setRedirectUri ( $ config [ $ key ] [ 'redirect_uris' ] [ 0 ] ) ; } } else { // new-style $ this -> setClientId ( $ config [ 'client_id' ] ) ; $ this -> setClientSecret ( $ config [ 'client_secret' ] ) ; if ( isset ( $ config [ 'redirect_uris' ] ) ) { $ this -> setRedirectUri ( $ config [ 'redirect_uris' ] [ 0 ] ) ; } } }
Set the auth config from new or deprecated JSON config.
This structure should match the file downloaded from
the "Download JSON" button on in the Google Developer
Console.
@param string|array $config the configuration json
@throws Google_Exception
Set the auth config from new or deprecated JSON config . This structure should match the file downloaded from the Download JSON button on in the Google Developer Console .