public static function chain()
    {
        $providers = func_get_args();
        if (empty($providers)) {
            throw new \InvalidArgumentException('No providers in chain');
        }

        return function () use ($providers) {
            $provider = array_shift($providers);
            $credentials = $provider();

            while (($provider = array_shift($providers))
                && !($credentials instanceof Credentials)
            ) {
                $credentials = $provider();
            }
            return $credentials;
        };
    }