diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index cc01f2b77..323848061 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -17,7 +17,6 @@ use Composer\Package\PackageInterface; use Composer\Package\AliasPackage; use Composer\Package\Version\VersionParser; use Composer\DependencyResolver\Pool; -use Composer\Downloader\TransportException; use Composer\Json\JsonFile; use Composer\Cache; use Composer\Config; @@ -499,18 +498,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository continue; } - // in case the remote filesystem responds with an 401 error ask for credentials - if($e instanceof TransportException && ($e->getCode() == 401)) - { - $this->io->write('Enter the access credentials needed to access the repository'); - $username = $this->io->ask('Username: '); - $password = $this->io->askAndHideAnswer('Password: '); - $this->rfs->setAuthentication($filename, $username, $password); - - // try fetching the file again - return $this->fetchFile($filename, $cacheKey, $sha256); - } - if ($e instanceof RepositorySecurityException) { throw $e; } diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 7411f6787..db41bdcfa 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -44,18 +44,6 @@ class RemoteFilesystem $this->options = $options; } - /** - * Set the authentication information for the repository. - * - * @param string $originUrl The origin URL - * @param string $username The username - * @param string $password The password - */ - public function setAuthentication($originUrl, $username, $password = null) - { - return $this->io->setAuthentication($originUrl, $username, $password); - } - /** * Copy the remote file in local. * @@ -137,6 +125,18 @@ class RemoteFilesystem if ($e instanceof TransportException && !empty($http_response_header[0])) { $e->setHeaders($http_response_header); } + + // in case the remote filesystem responds with an 401 error ask for credentials + if($e instanceof TransportException && ($e->getCode() == 401)) + { + $this->io->write('Enter the access credentials needed to access the resource at '.$originUrl); + $username = $this->io->ask('Username: '); + $password = $this->io->askAndHideAnswer('Password: '); + $this->io->setAuthentication($originUrl, $username, $password); + + // try getting the file again + return $this->get($originUrl, $fileUrl, $additionalOptions, $fileName, $progress); + } } if ($errorMessage && !ini_get('allow_url_fopen')) { $errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';