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
parent
0535473c6b
commit
f2afbbac2f
|
@ -17,6 +17,7 @@ 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;
|
||||
|
@ -498,6 +499,18 @@ 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;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,18 @@ 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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue