1
0
Fork 0

Extended the fetchFile() method of the ComposerRepository class to be

able to deal with http basic auth. In case the remote resource responds
with a 401 ask the user for access credentials and retry quering the
resource again.
pull/1657/head
Stephan Hochdörfer 2013-03-04 12:49:14 -05:00
parent 0535473c6b
commit f2afbbac2f
2 changed files with 25 additions and 0 deletions

View File

@ -17,6 +17,7 @@ use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\Downloader\TransportException;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Cache; use Composer\Cache;
use Composer\Config; use Composer\Config;
@ -498,6 +499,18 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
continue; 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) { if ($e instanceof RepositorySecurityException) {
throw $e; throw $e;
} }

View File

@ -44,6 +44,18 @@ class RemoteFilesystem
$this->options = $options; $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. * Copy the remote file in local.
* *