Authenticate the client, and return it.

@param string[] $config

@throws \InvalidArgumentException

@return \Github\Client
968805
public function authenticate(array $config)
    {
        if (!$this->client) {
            throw new InvalidArgumentException('The client instance was not given to the jwt authenticator.');
        }

        if (!array_key_exists('token', $config)) {
            throw new InvalidArgumentException('The jwt authenticator requires a token.');
        }

        $this->client->authenticate($config['token'], Client::AUTH_JWT);

        return $this->client;
    }
1081219
public static function factory($config = array()) {
        $default = array(
            'serverUrls' => null,
            'user' => null,
            'publicKey' => null,
            'privateKey' => null,
        );

        // Backwards-compatibility with old client where user === publicKey
        if (!isset($config['user']) && isset($config['publicKey'])) {
            $config['user'] = $config['publicKey'];
        }

        $required = array('serverUrls', 'publicKey', 'privateKey', 'user');
        $config = Collection::fromConfig($config, $default, $required);

        if (!is_array($serverUrls = $config->get('serverUrls')) || empty($serverUrls)) {
            throw new InvalidArgumentException('serverUrls must be an array');
        }

        // Create the client and attach the service description
        return new self($serverUrls[0], $config);
    }
1058179
public function createConnector( array $config )
	{
		if( !isset( $config['driver'] ) )
		{
			throw new InvalidArgumentException( 'A driver must be specified.' );
		}

		if( $this->container->getIs( $key = "db.connector.{$config['driver']}" ) )
		{
			return $this->container->get( $key );
		}

		switch( $config[ 'driver' ] ) {
			case 'mysql':
				return new MySqlConnector;
			/* TODO add support
			 * case 'pgsql':
				return new PostgresConnector;*/
		}

		throw new InvalidArgumentException( "Unsupported driver [{$config['driver']}]" );
	}
1208451
public function make(array $config): SearchClient
    {
        $config = $this->getConfig($config);

        return $this->getClient($config);
    }
1110256
protected function getClient(array $config)
    {
        $client = new CloudsearchClient( 
            $config['client_id'], 
            $config['client_secret'], 
            $config['host'],
            'aliyun'
        );

        $search = new CloudsearchSearch($client);
        $search->addIndex($config['app']);

        return $search;
    }
433796
public function make(array $config)
    {
        if (!isset($config['driver'])) {
            throw new InvalidArgumentException('A driver must be specified.');
        }

        return $this->factory($config['driver'])->make($config);
    }
469315
public function setConfig($config)
    {
        if (!is_array($config) && !$config instanceof ArrayAccess) {
            throw new InvalidArgumentException('Config has to be array or ArrayAccess');
        }
        $this->config = $config;

        return $this;
    }
768815
public static function configure(array $config)
    {
        if (!is_null(static::$instance)) {
            return static::$instance;
        }

        static::$config = $config;

        static::$session = Session::getInstance();

        return static::$instance = new Auth($config[$config['default']]);
    }
745903
public function setConfig($config)
    {
        if (is_string($config)) {
            // Treat the parameter as a filepath
            $this->config = $this->createConfig($config);
        } elseif (is_array($config)) {
            $this->config = $this->createConfig($config);
        } elseif ($config instanceof ConfigInterface) {
            $this->config = $config;
        } else {
            throw new InvalidArgumentException(sprintf(
                'Configset must be an associative array, a file path, or an instance of %s',
                ConfigInterface::class
            ));
        }

        return $this;
    }
1211776
public function create(array $config = [])
    {
        if (null === $this->handler) {
            $this->handler = DefaultHandler::create();
        }

        return new Client(
            array_merge_recursive(
                [
                    'verify'  => false,
                    'handler' => $this->handler,
                ],
                $config
            )
        );
    }
753028
protected function setAuthenticationHandler(array $config, Authentication $authentication = null)
    {
        $this->setAuthentication($config, $authentication);

        $authenticationHandler = new AuthenticationHandler();
        $authenticationHandler->setSigner($this->authentication);
        if (!isset($config['handler'])) {
            $config['handler'] = \GuzzleHttp\HandlerStack::create();
        }
        try {
            if (!($config['handler'] instanceof \GuzzleHttp\HandlerStack)) {
                $config['handler'] = \GuzzleHttp\HandlerStack::create($config['handler']);
            }
            $config['handler']->before('history', $authenticationHandler, 'authentication');
        } catch (\InvalidArgumentException $e) {
            // history middleware not added yet
            $config['handler']->push($authenticationHandler, 'authentication');
        }
        return $config;
    }
635306
public function setConfiguration($config)
    {
        // Load Util Classes / backwards compatibility
        if (is_string($config)) {
            $this->config = new Config (array('language' => $config));
            $this->translator = new Translator($this->config);
        } else if (is_array($config)) {
            $this->translator = new Translator($config);
        } else {
            throw new InvalidArgumentException("Please provide a string or an array as parameter!");
        }

        return $this;
    }
1158155
protected function getClient(array $config)
    {
        $name = array_get($config, 'connector');

        return $this->cache->driver($name)->getStore();
    }
241461
private function buildClient(array $config)
    {
        $client = ClientBuilder::create()
            ->setHosts($config['hosts']);

        if (isset($config['retries'])) {
            $client->setRetries($config['retries']);
        }

        if (isset($config['logging']) and $config['logging']['enabled'] == true) {
            $logger = ClientBuilder::defaultLogger($config['logging']['path'], $config['logging']['level']);
            $client->setLogger($logger);
        }

        return $client->build();
    }
814036
protected function makeBaseClient($config)
    {
        $parameters = $this->getParameters($config);

        $client = new Client($parameters);

        $this->attachSubscribers($client);

        return $client;
    }
1275937
public function authenticate(array $config)
    {
        if (!$this->client) {
            throw new InvalidArgumentException('The client instance was not given to the token authenticator.');
        }

        if (!array_key_exists('token', $config)) {
            throw new InvalidArgumentException('The token authenticator requires a token.');
        }

        $this->client->authenticate($config['token'], Client::AUTH_HTTP_TOKEN);

        return $this->client;
    }
812443
protected function getAuthClass(array $authConfig = []): Auth
    {
        $type = $authConfig['type'] ?? '';

        switch ($type) {
            case ClientCredentials::TYPE:
                return new ClientCredentials(
                    $authConfig['appId'],
                    $authConfig['appSecret']
                );
            case LegacyCredentials::TYPE:
                return new LegacyCredentials(
                    $authConfig['clientId'],
                    $authConfig['apiKey']
                );
            case RefreshCredentials::TYPE:
                return new RefreshCredentials(
                    $authConfig['appId'],
                    $authConfig['appSecret'],
                    $authConfig['refreshToken']
                );
            default:
                return new NullCredentials();
        }
    }